Hi @princesahu04,
I'm not sure I fully understand but you could combine a match_phrase
to declare the slop and a match
query to declare the minimum should match.
PUT test/_doc/1
{
"project": "token1 token2 token3 token4 token5"
}
The following query will return results:
GET test/_search
{
"query": {
"bool": {
"must": [
{
"match_phrase": {
"project": {
"query": "token1 token4 token5",
"slop": 3
}
}
},
{
"match": {
"project": {
"query": "token1 token4 token5",
"minimum_should_match": 3
}
}
}
]
}
}
}
Results:
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 2.5617933,
"hits" : [
{
"_index" : "test",
"_type" : "_doc",
"_id" : "1",
"_score" : 2.5617933,
"_source" : {
"project" : "token1 token2 token3 token4 token5"
}
}
]
}
}
But if the query contains only 2 terms it won't return results because it doesn't have the minimum should match terms:
GET test/_search
{
"query": {
"bool": {
"must": [
{
"match_phrase": {
"project": {
"query": "token1 token5",
"slop": 3
}
}
},
{
"match": {
"project": {
"query": "token1 token5",
"minimum_should_match": 3
}
}
}
]
}
}
}
Results:
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 0,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
}
}
I hope it helps!