# How to specify top\_terms\_N rewrite using Nest SDK?

**URL:** <https://discuss.elastic.co/t/how-to-specify-top-terms-n-rewrite-using-nest-sdk/77743>\
**Category:** Elasticsearch\
**Created:** [March 8, 2017, 12:57am UTC](https://discuss.elastic.co/t/how-to-specify-top-terms-n-rewrite-using-nest-sdk/77743 "2017-03-08T00:57:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sunil\_purushothaman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sunil_purushothaman/32/21596_2.png) [@sunil\_purushothaman](https://discuss.elastic.co/u/sunil_purushothaman)\
**Post date:** [March 8, 2017, 12:57am UTC](https://discuss.elastic.co/t/how-to-specify-top-terms-n-rewrite-using-nest-sdk/77743/1 "2017-03-08T00:57:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [March 27, 2017, 3:33am UTC](https://discuss.elastic.co/t/how-to-specify-top-terms-n-rewrite-using-nest-sdk/77743/2 "2017-03-27T03:33:03Z")

</div>

Unfortunately, this is a bug in NEST 😢 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](https://github.com/elastic/elasticsearch-net/issues/2688).

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [March 29, 2017, 6:16am UTC](https://discuss.elastic.co/t/how-to-specify-top-terms-n-rewrite-using-nest-sdk/77743/3 "2017-03-29T06:16:08Z")

</div>

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

> <https://github.com/elastic/elasticsearch-net/blob/5.x/src/Tests/QueryDsl/TermLevel/Wildcard/WildcardQueryUsageTests.cs#L35-L42>

Thank you for raising this 👍

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [March 30, 2017, 7:19am UTC](https://discuss.elastic.co/t/how-to-specify-top-terms-n-rewrite-using-nest-sdk/77743/4 "2017-03-30T07:19:43Z")

</div>

[This is now in 5.3.0 on Nuget](https://www.nuget.org/packages/NEST/5.3.0)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 27, 2017, 7:20am UTC](https://discuss.elastic.co/t/how-to-specify-top-terms-n-rewrite-using-nest-sdk/77743/5 "2017-04-27T07:20:18Z")

</div>

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