My Elasticsearch (v5.4.1) documents have a _patents
field as such :
{
// (Other fields : title, text, date, etc.)
,
"_patents": [
{"cc": "US"},
{"cc": "MX"},
{"cc": "KR"},
{"cc": "JP"},
{"cc": "CN"},
{"cc": "CA"},
{"cc": "AU"},
{"cc": "AR"}
]
}
I'm trying to build a query that would return only documents whose patents match an array of country codes.
For instance, if my filter is ["US","AU"]
I need to be returned all documents that have patents in US
and in AU
. Exclude documents that have US
but not AU
.
So far I have tried to add a "term" field to my current working query :
{
"query": {
"bool": {
"must": [
// (Other conditions here : title match, text match, date range, etc.) These work
,
{
"terms": {
"_patents.cc": [ // I tried just "_patents"
"US",
"AU"
]
}
}
]
}
}
}
Or this, as a filter :
{
"query": {
"bool": {
"must": [...],
"filter": {
"terms": {
"_patents": [
"US",
"AU"
]
}
}
}
}
}
These queries and the variants I've tried don't produce an error, but return 0 result.
I can't change my ES document model to something easier to match, like "_patents": [ "US","CA", "AU", "CN", "JP" ]
because this is a populated field. At indexation time, I populate and reference Patent
documents that have many fields, including cc
.