Hi,
I have following mapping :
> PUT products
> {
> "mappings" : {
> "properties" : {
> "item_name" : {"type" : "keyword"},
> "catalog_name" : {"type" : "keyword"},
> "group" : {"type" : "keyword"},
> "location" : {"type" : "keyword"},
> "price" : {"type" : "double"}
> }
> }
> }
and below are the docs of the products index
> POST /products/_bulk
> {"index":{}}
> {"item_name":"item1", "catalog" : "catalog1", "location" : "india", "price": 100}
> {"index":{}}
> {"item_name":"item2", "catalog" : "catalog1", "location" : "india", "price": 200}
> {"index":{}}
> {"item_name":"item1", "catalog" : "catalog1", "group" : "gold", "price": 90}
Item | Catalog | group | location | price
Item1 | 1.0 | - | india | 100
Item2 | 1.0 | - | india | 200
Item1 | 2.0 | gold | - | 90
following is my query:
GET /products/_search
{
"query": {"bool": {"must": [
{"boosting":
{
"positive": {"term": {
"group": {
"value": "gold"
}
}},
"negative": {"term": {
"location": {
"value": "india"
}
}},
"negative_boost": 0.5
}}
]}}
}
the above search query is resulting in:
Item | Catalog | group | location | price
Item1 | 2.0 | gold | - | 90
but what I want is:
Item | Catalog | group | location | price
Item2 | 1.0 | - | india | 200
Item1 | 2.0 | gold | - | 90
If the user belongs to gold group and lives in india, priority should be given to gold group item1 and then location.
Can anyone please let me know how to write a query for such a scenario? Thanks in advance.