NEST Term query - incorrectly generated JSON?

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?

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.

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