elasticsearchnestelasticsearch-2.0nest2

What is the replacement for FuzzyMinimumSimilarity in Nest 2, Elasticsearch 2.3?


I'm upgrading to Nest 2 (elasticsearch 1.x to 2.3), but notice on breaking changes that FuzzyMinimumSimilarity and OnFieldsWithBoost are gone. How should i replace this code below to Nest v2?

new SearchDescriptor<T>().Type(searchTypes).Query(q =>q.QueryString(qs => qs.Query(fuzzy).FuzzyMinimumSimilarity(0.7)));

And for FuzzyMaxExpansions(0.7)


Solution

  • Here are the fuzziness options available on query_string query in NEST 2.x (use latest 2.5.8)

    var client = new ElasticClient();
    
    var searchResponse = client.Search<MyDocument>(s => s
        .Query(q => q
            .QueryString(qs =>qs
                .Fields(f => f
                    .Field(ff => ff.Name, 3)
                    .Field(ff => ff.Content, 0.5)
                )
                .Query("fuzzy")
                .Fuzziness(Fuzziness.EditDistance(3))
                .FuzzyMaxExpansions(2)
                .FuzzyPrefixLength(4)
                .FuzzyRewrite(MultiTermQueryRewrite.TopTerms(3))
            )
        )
    );
    

    which yields

    {
      "query": {
        "query_string": {
          "query": "fuzzy",
          "fuzzy_max_expansions": 2,
          "fuzziness": 3,
          "fuzzy_prefix_length": 4,
          "fields": [
            "name^3",
            "content^0.5"
          ],
          "fuzzy_rewrite": "top_terms_3"
        }
      }
    }
    

    Also take a look at the release blog post and breaking changes between 1.x and 2.x documentation