I have an object
{
"id": "first",
"field": [
{
"subfield": "0"
},
{
"subfield": "1"
},
{
"subfield": "2"
}
]
}
I want to search field.subfield =1 and also field.subfield!=1
Where both cases should return this item.
For equal it's easy. I can use QueryBuilders.boolQuery().filter(QueryBuilders.termsQuery("field.subfield", 1));
But not equal is problematic as this
QueryBuilders.boolQuery().mustNot(QueryBuilders.termsQuery("field.subfield", 1));
does not return this item as one item in array is 1.
I'm looking for someway to filter item only if ALL items in array equal 1.
So mixed should still be returned.
The reindex operation may take a while, but it is a one time thing and after that you can query the nested objects.
Script queries can be computationally expensive, and they may take a long time if you want to run those against a lot of documents (as Elasticsearch will basically have to execute the query against each of your documents every time you use this query).
Maybe you can test if the script query performance is acceptable on your dataset? If it works well for you, then that's great. Maybe a hybrid approach works for you: use a script query until such time that you will have to reindex anyway (for an upgrade or something like that)?
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.