The following 1.7 Query DSL (php-client formatted) code makes use of the "terms" filter and execution "and" to require all terms to be found in documents. With the "terms" breaking change in 2.1.1 I need to rewrite the query. It appears that "terms" in 2.1.1 is only good for finding documents with "any" of the terms provided, which raises some questions about how to convert code like this.
- Is the new best practice to separate all the "terms" formerly executed with "and" into separate "term" filters, and then wrap all the "term" filters in "and" query? You can see my updated 2.1.1 query below. Seems to work, but I wonder if this is the new best practice for handling of "terms" filtered queries, formerly executed with "and"?
1.7 Query DSL
$query = [
'query' => [
'filtered' => [
'filter' => [
'bool' => [
'must' => [
[
'term' => [
'award_sku' => (string) $data['award_sku']
]
],
[
'term' => [
'class' => (string) $data['class']
]
],
[
'terms' => [
'params' => $data['params'],
'execution' => 'and',
'_cache' => true
]
],
[
'term' => [
'params_count' => $data['params_count']
]
]
],
'_cache' => true
]
]
]
]
];
2.1.1 Query DSL (so far)
$query = [
'query' => [
'bool' => [
'filter' => [
'and' => [
[
'term' => [
'award_sku' => (string) $data['award_sku']
]
],
[
'term' => [
'class' => (string) $data['class']
]
],
[
'term' => [
'params_count' => $data['params_count']
]
],
[
'term' => [
'params' => $param1
]
],
[
'term' => [
'params' => $param2
]
]
]
]
]
]
];