Location 4: smithNow our phrase match cannot match this document, because the distance between abraham and lincoln is 100. You must add a slop value of 100 to match.
The Closer the better (Closer is better)Phrase Query simply removes documents that do not contain a specific Query Phrase, and Proximity Query) -A phrase query with a slop value greater than 0 takes the closeness of the query entry into consideration the final relevance score. By setting a high slop value such as 50 or 100, you can exclude documents with words too far, but also give documents with adjacent words a higher score.
The proximity query for quick dog matches two documents containing quick and dog, but gives quick and dog a higher score:
POST /my_index/my_type/_search{ "query": { "match_phrase": { "title": { "query": "quick dog", "slop": 50 } } }}
{ "hits": [ { "_id": "3", "_score": 0.75, "_source": { "title": "The quick brown fox jumps over the quick dog" } }, { "_id": "2", "_score": 0.28347334, "_source": { "title": "The quick brown fox jumps over the lazy dog" } } ]}
Use closeness to improve relevanceAlthough Proximity Query is useful, all entries must appear in the document. This requirement is too strict. This problem is similar to what we have discussed in the Controlling Precision section of the Full-Text Search chapter: If six of the seven entries match, this document may be relevant to the user, but the match_phrase query will exclude it.
Compared with the proximity matching as an absolute requirement, we can regard it as a Signal-as a member of many potential matches, contribute to the final score of each document (refer to Most Fields (Most Fields )).
The fact that we need to accumulate the scores of multiple queries indicates that we should use bool queries to merge them.
We can use a simple match query as an must clause. This query is used to determine which documents need to be included in the result set. The minimum_should_match parameter can be used to remove Long tail ). Then we add more specific queries in the form of a shocould clause. Each document that matches the shocould clause will increase its relevance.
GET /my_index/my_type/_search{ "query": { "bool": { "must": { "match": { "title": { "query": "quick brown fox", "minimum_should_match": "30%" } } }, "should": { "match_phrase": { "title": { "query": "quick brown fox", "slop": 50 } } } } }}
There is no doubt that we can add other queries to the shocould clause. Each query is used to increase the relevance of a specific type.