Reputation: 762
I want to write a query in elasticsearch only for scoring can anybody please tell me how can i do that my query is given below also "minimum_should_match": 0 is not working with should, if any query matches both area2 and area1 then i want to boost the score of the result now how can i achieve that can anybody tel me the final query which i should write ??
query: {
bool: {
must: [
{
query_string: {
query: shop_search,
fields: ['shop_name'],
boost: 30.0
}
},
{
bool: {
should: [
{
term : { 'address.area2' : search_area2 },
term : { "address.area1" : search_area1 }
},
"minimum_should_match" : 0,
],
}
}
]
}
Upvotes: 0
Views: 257
Reputation: 1166
Do you want to get all records that match the shop search and boost the results where the the address.area1 and/or address.area2 field values match the area searches?
The syntax you are using for the bool
is off. The match clause needs to be fixed up to fit Elasticsearch's expectations and the extra nested bool
should not be necessary. See Elasticsearch Bool Query.
{
"query" : {
"bool" : {
"must" : {
"query_string" : {
"query" : <SHOP_SEARCH>,
"fields" : ['shop_name']
}
},
"should" : [
{
"match" : {
"address.area1" : {
"query" : <SEARCH_AREA1>,
"operator" : "and",
"boost" : <CUSTOM_BOOST1>
}
}
},
{
"match" : {
"address.area2" : {
"query" : <SEARCH_AREA2>,
"operator" : "and",
"boost" : <CUSTOM_BOOST2>
}
}
}
]
}
}
}
I think with that query, you can expect the the following:
You might want to review everything you are getting with query_string
.
Upvotes: 1