Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

chrislentz's avatar

How do you do field boosting in the Elasticsearch PHP client?

I am using Elasticsearch for the first time and have the indexing and basic searching down, but I am looking todo some complex searching.

With the PHP client how do you do partial searches and field boosting / relevance? Ultimately, I want to search multiple fields for partial matches, exact matches, and boost some of the fields.

Here is what I have so far, but I can't get it working. The Elasticsearch documentation is no good.

$show_params = [
    'index' => env('ES_INDEX'),
    'type' => 'show',
    'size' => 6,
    'body' => [
        'query' => [
            'bool' => [
                'should' => [
                    [
                        'match' => [
                            'title' => [
                                'query' => '*' . $q . '*',
                                'boost' => 2
                            ]
                        ]
                    ],
                    [
                        'match' => [
                            'synopsis' => '*' . $q . '*'
                        ]
                    ]
                ]
            ]
        ]
    ]
];

$client = \Elasticsearch\ClientBuilder::create()->build();

$show_raw_results = $client->search($show_params);
0 likes
0 replies

Please or to participate in this conversation.