1

We are in the process of upgrading ElasticSearch and NEST from 1.6.2 -> 2.3.3.

What replaces how we do TermsExecution.And in 2.3.3?

How can this be easily done with an unknown number of terms that need to match? e.g. before you were able to just pass in an array.

Ben Wilde
  • 5,552
  • 2
  • 39
  • 36
Antony Francis
  • 304
  • 1
  • 7

1 Answers1

2

TermsExecution.And on a terms query should be converted to a bool query with a conjunction of must (or filter, depending on query/filter context) queries, with each query being a term query on an individual value.

For example,

client.Search<dynamic>(s => s
    .Query(q => +q
        .Term("field", "value1")
        && +q
        .Term("field", "value2")
    )
);

yields

{
  "query": {
    "bool": {
      "filter": [
        {
          "term": {
            "field": {
              "value": "value1"
            }
          }
        },
        {
          "term": {
            "field": {
              "value": "value2"
            }
          }
        }
      ]
    }
  }
}
Russ Cam
  • 124,184
  • 33
  • 204
  • 266