ES bool and match when should be used? - elasticsearch

I got that bool has different options which influences scoring. In the other hand, match has other options like lenient, minimum_should_match, operator.
What is the real use of these two? Can we have one to satisfy all of these things?
Is my understanding wrong? When should I use bool and match?

Bool is used to combine different queries. It provides below options
1. Must :
The clause (query) must appear in matching documents and will contribute to the score.
It works like "AND" for different queries
Filter:
The clause (query) must appear in matching documents. However unlike must the score of the query will be ignored
It works like "AND" but doesn't calculate score
Should :
The clause (query) should appear in the matching document.
It works like "OR" for multiple queries
Must_not:
The clause (query) must not appear in the matching documents. Clauses are executed in filter context meaning that scoring is ignored
Match Query
It is used for performing full text search
If you need a query to do full text search on a single field , you can use match query. If you need more than one query say a exact match on field(term query) and partial match on another field (match query). You will have to combine them using Bool clause.

Related

ElasticSearch: term vs match query decision

Being new to ElasticSearch, need help in my understanding.
What I read about term vs match query is that term query is used for exact match and match query is used when we are searching for a term and want result based on a relevancy score.
But if we already defined a mapping for a field as a keyword, why anyone has to decide upon between term vs match, wouldn't it be always a term query in case mapping is defined as a keyword?
What are the use cases where someone will make a match query on the keyword mapping field?
The same confusion is vice versa.
A text field will be analyzed (transformed, split) to generate N tokens, and the keyword itself will become a token with no transformations. At the end, you have N tokens referencing a document.
Then.
By doing a match query, you will treat your query as a text as well, by analyzing it before performing the matching (transforming it), and the term will not.
You can create a field with a term mapping, but then perform a match query on top of it (for example if you want to be case insensitive), and you can create a text mapping for a n-gram and perform a term query to match exactly what you're asking for.

Is there performance difference between constant_score and bool query using filter?

When it comes to the "performance difference", I read nothing reliable till now.
Based on its official docs, as to filter used in the bool query
The clause (query) must appear in matching documents. However unlike must the score of the query will be ignored. Filter clauses are executed in filter context, meaning that scoring is ignored and clauses are considered for caching.
As for constant score query
Filter queries do not calculate relevance scores. To speed up performance, Elasticsearch automatically caches frequently used filter queries.
Just a guess
Constant query will not calculate (TF-IDF or more advanced algs), while the bool query will do the calculation but return 0 (ignoring it); so the constant query is more performant.
Besides when it comes to a specified score, you have to use constant score query instead of bool query which only will return 0.
QAs I just read: Elasticsearch : constant_score query vs bool.filter query
NO, there is no performance difference since they are the same.
Based on again its offical doc discussing about filter context:
In a filter context, a query clause answers the question “Does this document match this query clause?” The answer is a simple Yes or No — no scores are calculated.
And
Filter context is in effect whenever a query clause is passed to a filter parameter, such as the filter or must_not parameters in the bool query, the filter parameter in the constant_score query, or the filter aggregation.

Filter context for should in bool query

Elasticsearch documentation says
If the bool query is a filter context or has neither must or filter then at least one of the should queries must match a document for it to match the bool query.
So I can have a bool query with a should clause along with must or filter within a filter context and then still get an exact match. How to do this combination?
I would also be interested in knowing how to do this with Jest client?
In that case you need to add minimum_should_match: 1 if you want that at least one of your should clauses match.

ElasticSearch - Simultaneous (case sensitive) Term and (case insensitive) Match search on same property

How can one search trough the same property with both a case-sensitive Term query and a case insensitive Match query?
We have a Tags property that for several reasons we need to make case-sensitive. So we would like to search trough in this manner using relevance boosting to put the exact Term matches at the top while the potentially less relevant results with different casing lower in the results.
I know that the lowercase filter for index analysis allows for case-insensitive searching using Match queries, but as I mentioned we need to keep the Tags case-sensitive.
For now we use a keyword analyzer without lowercase filter on the tags to provide exact Term matches that are case-sensitive. Adding a Match query to that is useless because it is comparing against cased tokens.
Is there a way to achieve this?

Difference between boolean query and term query

Difference between boolean query and term query.
As far as my understanding boolean query is combination of one or more query and term query is single query to match particular field.Am in right?
Thanks in Advance..!
A bool query literally combines multiple queries of any type together with clauses such as must, must_not, and should.
A term query specifies a single field and a single term to determine if the field matches. Note that term queries are specifically for non-analyzed fields.

Resources