So what I'm trying to achieve is partial matching with customized searchable fields per index.
I generate a match_phrase_prefix
with the value to search, and if it is more than one word, I generate another one per word.(I could use prefix
, but it bugged, or has undocumented settings).
In this case, I'm trying to look up for "belden cable"
; the query looks like this:
{
"query":{
"bool":{
"should":
[
{
"indices":{
"indices":["addresss"],
"query":{
"bool":{
"should":
[
{"match_phrase_prefix":{"name":"BELDEN CABLE"}}
{"match_phrase_prefix":{"name":"BELDEN"}},
{"match_phrase_prefix":{"name":"CABLE"}}
]
}
},
"no_match_query":"none"
}
},
{
"indices":{
"indices":["customers"],
"query":{
"bool":{
"should":[
{"match_phrase_prefix":{"_all":"BELDEN CABLE"}},
{"match_phrase_prefix":{"_all":"CABLE"}},
{"match_phrase_prefix":{"_all":"BELDEN"}}
]
}
},
"no_match_query":"none"
}
}
]
}
}
My target search is to get the results that have "belden cable"
first, then the searches for just "belden"
or "cable"
.
This returns(by example) 4 results that have "belden cable"
, then a result that has only "cable"
, then more results of "belden cable"
.
How can I boost the results that have the complete value of the search?("belden cable")
I've tried separating the indices query of both words and separated words, but it gives worst relevance results.
Also I've tried using a boost statement inside the match_phrase_prefix
for "belden cable"
without change in the results..
What you actually need is a different way of analyzing the input data. See below something that should be a starting point to your final solution (because you need to consider the full set of requirements for your queries and data analysis). Searching with ES is not only about queries, but also about how you structure and prepare the data.
The idea is that you want your data to be analyzed so that
belden cable
stays as is. With a mapping of"name": {"type": "string"}
thestandard
analyzer is being used which means that the list of terms in your index isbelden
andcable
. What you actually need is [belden cable
,belden
,cable
]. So, I thought on suggesting theshingles
token filter.