# NEST Term query - incorrectly generated JSON?

**URL:** <https://discuss.elastic.co/t/nest-term-query-incorrectly-generated-json/121908>\
**Category:** Elasticsearch\
**Created:** [February 28, 2018, 5:33pm UTC](https://discuss.elastic.co/t/nest-term-query-incorrectly-generated-json/121908 "2018-02-28T17:33:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dave\_Russell](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dave_russell/32/42250_2.png) [@Dave\_Russell](https://discuss.elastic.co/u/Dave_Russell)\
**Post date:** [February 28, 2018, 5:33pm UTC](https://discuss.elastic.co/t/nest-term-query-incorrectly-generated-json/121908/1 "2018-02-28T17:33:28Z")

</div>

I'm a C# / Web / Javascript developer. I originally wrote an ElasticSearch app years ago on v2. I'm now building a new app with v6.2 but trying to use some of the same NEST code from before.  
Some of this code is for building combined term-based queries based on selections made client-side.  
What's happening is this:  
I'm building my query in NEST - it's parameter driven, so field/value are all parameters.  
compoundQuery |= new BoolQuery  
{  
Should = new QueryContainer[] {  
new TermQuery()  
{  
Field = tv.FieldName,  
Value = tv.Value,  
},  
}  
....which according to the docs should result in this JSON....  
{  
"term": {  
"fieldname": {  
"value": "myvaluegoeshere"  
}  
}  
}  
....but is ACTUALLY resulting in this JSON......  
"term": {  
"fieldname": {  
"value": [  
"myvaluegoeshere"  
]  
}  
}

NOTE: The extra array modifier around the [value].

The query still seems to be valid, but it doesn't find anything, whereas the "correct" query - without the [] - works and _does_ find matching documents.

How do I get the query I want using NEST?

---

<div class="post-metadata">

**Author:** ![Dave\_Russell](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dave_russell/32/42250_2.png) [@Dave\_Russell](https://discuss.elastic.co/u/Dave_Russell)\
**Post date:** [February 28, 2018, 5:43pm UTC](https://discuss.elastic.co/t/nest-term-query-incorrectly-generated-json/121908/2 "2018-02-28T17:43:43Z")

</div>

Isn't it always the way.  
You spend hours on something then post it to the forums, only to realise exactly what the problem is immediately after you've posted it.  
Ignore me.  
My "value" was an object which was being set as a string array, not a string, by the modelbinder so I'm an idiot and it's fixed now.

---

<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:** [March 28, 2018, 5:43pm UTC](https://discuss.elastic.co/t/nest-term-query-incorrectly-generated-json/121908/3 "2018-03-28T17:43:49Z")

</div>

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