Query boost issues

Hello,
i have some issues with query boosting, here is my search request in PHP:

        $params = [
        'index' => 'formations',
        'type' => 'all',
        "from" => 0, "size" => 40,
        "body" => [
            "query" => [
                "bool" => [
                    "should" => [
                        "multi_match" => [
                            "fields" => ["name^150", "cities^110"],
                            "query" => $request->research
                        ]
                    ]
                ]
            ],
            "highlight" =>[
                "pre_tags" => ['<strong class="text-primary">'],
                "post_tags" => ['</strong>'],
                'fields' => [
                    'villes' => new \stdClass(),
                ],
            ]
        ]
        ];

When i apply a boost of 150 on the name field, its all working fine, guessing im typing 'bartender' in research bar. If i add a city to the research like 'bartender chicago' , all results containing the word bartender will come first ,I want that if the search contains the 2 keywords it will come first in the results.
But if i apply a boost > 150 on the city, if i type any name and Chicago, it will always show results with chicago first

Can someone explain me how i can do that ?
Here an example of the data i push :
$data = [
'body' => [
'id' => 1,
'intitule' => "bartender",
'cities' => ['chicago', 'new York'],
'index' => "formations",
'type' => 'all',
'id' => 1,
];
$data = [
'body' => [
'id' => 2,
'intitule' => "bartender",
'cities' => ['new York'],
'index' => "formations",
'type' => 'all',
'id' => 2,
];

Thanks a lot,
sorry for my english

I think the right approach is not to boost on each fields individually, but add a new multi_match clause of type cross_fields.

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html#type-cross-fields

        "query" => [
            "bool" => [
                "should" => [
                    "multi_match" => [
                        "fields" => ["name", "cities"],
                        "query" => $request->research
                    ],
                    "multi_match" => [
                        "type" => "cross_fields",
                        "fields" => ["name", "cities"],
                        "query" => $request->research,
                        "operator": "AND",
                        "boost" => 3
                    ]
                ]
            ]
        ]
1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.