Antony Francis
Antony Francis

Reputation: 304

What replaces TermsExecution.And in NEST 2.3.3 (upgrading from NEST 1.6.2)

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.

Upvotes: 1

Views: 99

Answers (1)

Russ Cam
Russ Cam

Reputation: 125528

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"
            }
          }
        }
      ]
    }
  }
}

Upvotes: 2

Related Questions