How to specify top_terms_N rewrite using Nest SDK?

I have this query in elastic DSL.

POST my-index/_search
{
  "query": {
    "wildcard": {
      "Author": {
        "value": "*joe*",
        "rewrite": "top_terms_15"
      }
    }
  }
}

I want to write the same query using Nest SDK, something like the following

private Nest.WildcardQuery CreateQuery()
{
    Nest.WildcardQuery query = new Nest.WildcardQuery();
    query.Field = "Author";
    query.Value = "*joe*";           

    query.Rewrite = Nest.RewriteMultiTerm.TopTermsN;
    //Now how to specify a value for N ? 

    return query;
}

How can I specify a value for N ? (when using Nest.RewriteMultiTerm.TopTermsN)

Elastic version 5.2.1 Kibana version 5.2.1 Nest version 5.2.0

Unfortunately, this is a bug in NEST :cry: With RewriteMultiTerm specified as an enum value, it's not possible to provide a value for N - I've opened an issue to address this for the next releases.

In the meantime, you can workaround this by using the low client exposed on NEST

var response = client.LowLevel.Search<SearchResponse<object>>("my-index",	
@"{
	""query"": {
		""wildcard"": {
			""Author"": {
				""value"": ""*joe*"",
    			""rewrite"": ""top_terms_15""
	        }
		}
	}
}");

// a search response that you would be returned from a NEST search query
var nestResponse = response.Body;

In using the low level client on NEST, you can still return a SearchResponse<T> as you would have expected from a search query with NEST. You can specify the query with an anonymous type if you prefer but I have used a string here.

This will be fixed in the next 5.x release, using a new MultiTermQueryRewrite type:

Thank you for raising this :thumbsup:

This is now in 5.3.0 on Nuget

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.