Full Text Queries - Match Flashcards
What is
A match query is typically used to search for full-text content, and it is well-suited for performing searches that involve analyzing text
Basic Match Query
{
“query”: {
“match”: {
“content”: “Elasticsearch tutorial”
}
}
}
This will return documents where the field content contains the terms “Elasticsearch” and “tutorial” (independently of order or proximity).
Match Phrase Query
{
“query”: {
“match_phrase”: {
“content”: “Elasticsearch tutorial”
}
}
}
This query matches documents where the content field contains “Elasticsearch tutorial” exactly, in that specific order. If the terms are out of order or have intervening words, the document won’t match.
Match with Fuzziness
{
“query”: {
“match”: {
“content”: {
“query”: “Elastsearch”,
“fuzziness”: “AUTO”
}
}
}
}
This will search for terms similar to “Elastsearch,” allowing for minor spelling errors (such as “Elasticsearch”).
Match with Operator (AND/OR)
The operator parameter controls how terms in the query are combined (with a logical AND or OR).
AND (default): All the terms in the query must be present in the document.
OR: Any of the terms in the query can appear in the document.
{
“query”: {
“match”: {
“content”: {
“query”: “Elasticsearch tutorial”,
“operator”: “and”
}
}
}
}
This query will only match documents that contain both “Elasticsearch” and “tutorial” (must be present in the document).
Match with Boosting
{
“query”: {
“match”: {
“content”: {
“query”: “Elasticsearch tutorial”,
“boost”: 2.0
}
}
}
}
This will give extra weight (boost) to documents matching the term “Elasticsearch tutorial.”
Match Phrase Prefix Query
{
“query”: {
“match_phrase_prefix”: {
“content”: “Elasticsearch tuto”
}
}
}
This will match documents where the content field contains a phrase starting with “Elasticsearch” and followed by words starting with “tuto” (like “tutorial” or “touch”).