We are trying to find out which documents in our search results include all the tokens in our search query. For example when running the following query:
GET /test/_search
{
"query" : {
"match" : { "message" : { "query": "the brown fox" } }
}
}
We would need a response like this (only the hits array is included with minimal fields for brevity):
"hits" : [
{
**"all_tokens_match": true**,
"_source" : {
"message" : "The Quick Brown Fox"
}
},
{
**"all_tokens_match": false**,
"_source" : {
"message" : "The Brown Bear"
}
}
]
How would you recommend we approach this kind of problem on Elasticsearch? We were looking into scripting but our field is usually indexed as a "text" and not as a "keyword" field and there seems to be some limitations with scripting in that case. In case you recommend scripting, we would be grateful for a snippet to guide us in the right direction. Thank you in advance for your support.
Check if named queries will help your problem.
If you use named queries, you would need to break your tokens into distinct queries, something like this:
Thank you @mayya for guiding us in the right direction of named queries. It helped us tackle our problem after we combined named queries with the "minimum_should_match" parameter and set "boost": 0 to avoid it affecting the score of our main query.
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.