I am new into the Elasticsearch world need help in understanding the "bool" query "should" clause, as mentioned in few blogs and documentation, "Should" Clause in elasticsearch is like OR condition, where at least one or more conditions should be true to get the response depending on the "minimum_should_match" parameter.
The way i am visualizing OR condition in elasticsearch query is like Java OR condition where it will exit the flow with first encounter of True condition (1 in above code example), skipping remaining part of the flow. But with examples provided in Documentation It is clear that it is executing all the conditions, How can i avoid it??
Thanks @Christian_Dahlqvist for the reply, yes I am more concerned about the performance of the query as i have millions of record, which is growing large day by day.
Requirement is If Match is happend for first match clause then I don't want check remaining match cases of Query because of it will decrease search performance and it will increase documents count. Expectation is Should work like java IF condition.
Expected output is
"matched_queries": ["4.WordMatch"]
or
"matched_queries": ["4.exactMatch"]
Or Is there anyway i can optimise this, so i get best performance out of it.??
I am not sure I understand what the problem is. Can you please provide a minimal recreation example with data and query and show what result you are getting and what you are expecting?
minimum_should_match indicates that at least one of the two should clauses should match, not that it should only return 1 document, so I believe what you are seeing is correct. If you are looking to only return a single match as quickly as possible, you might be able to run a filter query with size set to 1.
I think it should be enough to create a filter (so score does not have to be calculated for all hits), and then set size for the query to the number of results you want back.
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.