Hi All,
Am new to elastic search. Can you please let us know is it possible to write single query for exact match and partial match.
My secanrio: if there is no documents found for exact match it has returns the partial match records
THnaks,
Sagar
Hi All,
Am new to elastic search. Can you please let us know is it possible to write single query for exact match and partial match.
My secanrio: if there is no documents found for exact match it has returns the partial match records
THnaks,
Sagar
You can use a bool query with 2 should clauses. At least one clause has to be satisfied.
You can boost the exact match clause so results will appear on top.
https://www.elastic.co/guide/en/elasticsearch/reference/2.3/query-dsl-bool-query.html
HTH
Thanks for the reply. If my first condition returns results I don't want get records from second. Will it be possible
No. The normal way to handle this is to put a large boost on the query you'd prefer to match and just sort by score (the default). You can even use a constant score query to remove the regular scoring and just use the boosts, but I don't think that is a great idea usually.
If you really really want to remove hits that only match the second query you can use named queries to see which of your queries you matched which hit and do the filtering in your application. It is usually simpler to just use score though.
Thank you
© 2020. All Rights Reserved - Elasticsearch
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.