1

I have one field in my elastic search which is visibility_boosters which has two properties country_id and booster_rate.

I want to apply multi match query with these two fields (country_id and booster_rate).

country_id is dynamic and Visibility booster criteria are as below :

0 % => 0 | 5 % => +2 | 10 % => +4 | 15 % => +6 | 20 % => +8

Like if visibility booster is 5% then boost will be 2, if visibility booster is 10% then boost will be 4.

If both field matched based on that I want to boost that doc.

I have tried below solution but does not work for me.

My Query :

if ($country && $country != null) {
            $params['body']['query']['bool']['should'][] = [
                "bool" => [
                    "must" => [
                        [ "match" => [ "visibility_boosters.country_id" => $country->id ] ],
                        [ "match" => [ "visibility_boosters.booster_rate" => 5 ] ],
                    ],
                    "boost" => 2.0
                ]
            ];
            $params['body']['query']['bool']['should'][] = [
                "bool" => [
                    "must" => [
                        [ "match" => [ "visibility_boosters.country_id" => $country->id ] ],
                        [ "match" => [ "visibility_boosters.booster_rate" => 10 ] ],
                    ],
                    "boost" => 4.0
                ]
            ];
            $params['body']['query']['bool']['should'][] = [
                "bool" => [
                    "must" => [
                        [ "match" => [ "visibility_boosters.country_id" => $country->id ] ],
                        [ "match" => [ "visibility_boosters.booster_rate" => 15 ] ],
                    ],
                    "boost" => 6.0
                ]
            ];
            $params['body']['query']['bool']['should'][] = [
                "bool" => [
                    "must" => [
                        [ "match" => [ "visibility_boosters.country_id" => $country->id ] ],
                        [ "match" => [ "visibility_boosters.booster_rate" => 20 ] ],
                    ],
                    "boost" => 8.0
                ]
            ];
        }

These query applies to only one match query, if one query match then it is boosting the doc. I want that if both condition matched then based on visibility criteria boost that doc.

sehe
  • 374,641
  • 47
  • 450
  • 633
Kajal Pandya
  • 75
  • 1
  • 7

1 Answers1

0

The best way to get the query is right behind the Kibana search. Do to Kibana discover, and select your index. Add filters with conditions you require. you can also add search patterns for the required data and click Refresh. Once your data is showed in page, Go to Inspect in top right corner. Go to Request. Look for query in JSON format, You get the query you wanted, and use it wherever u need for API or other integrated systems.