Match phrase query

When you want to match a sequence of words, as opposed to separate terms in document, the match_phrase query can be useful.

For example, the following text is present as part of the description for one of the products:

real video saltware aquarium on your desktop!

What we want are all the products that have this exact sequence of words right next to each other: real video saltware aquarium. We can use the match_phrase query to achieve it. The match query will not work, as it doesn't consider the sequence of terms and their proximity to each other. The match query can include all those documents that have any of the terms, even when they are out of order within the document:

GET /amazon_products/_search
{
"query": {
"match_phrase": {
"description": {
"query": "real video saltware aquarium"
}
}
}
}

The response will look like the following:

{
...,
"hits": {
"total": 1,
"max_score": 22.338196,
"hits": [
{
"_index": "amazon_products",
"_type": "products",
"_id": "AV5rBfasNI_2eZGciIbg",
"_score": 22.338196,
"_source": {
"price": "19.95",
"description": "real video saltware aquarium on your desktop!product information see real fish swimming on your desktop in full-motion video! you'll find exotic saltwater fish such as sharks angelfish and more! enjoy the beauty and serenity of a real aquarium at yourdeskt",
"id": "b00004t2un",
"title": "sales skills 2.0 ages 10+",
"manufacturer": "victory multimedia",
"tags": []
}
}
]
}
}

The match_phrase query also supports the slop parameter, which allows you to specify an integer: 0, 1, 2, 3, and so on. slop relaxes the number of words/terms that can be skipped at the time of querying.

For example, a slop value of 1 would allow one missing word in the search text but would still match the document:

GET /amazon_products/_search
{
"query": {
"match_phrase": {
"description": {
"query": "real video aquarium",
"slop": 1
}
}
}
}

slop value of 1 would allow the user to search with real video aquarium or real saltware aquarium and still match the document that contains the exact phrase real video saltware aquarium. The default value of slop is zero.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.229.86