Search code examples
symfonyboostelastica

I'm indexing 4 different entities in Elastica search, is it possible to add different boost for one of them?


I'm using Symfony 5.4. Indexing Item, Product, Event and Test entities. Since Test don't have content property, i want to add higher boost to Test title property, but i don't find information if it is event possible. Someone had same problem?

I tried adding this condition in main query, but what it applies higher boost to all Entities if one of them is Test.

if ($this->indexManager->getIndex('test')) {`
    `$matchPhrase = new MatchPhrase();`
    `$matchPhrase->setFieldQuery('title.raw', $term);`
    `$matchPhrase->setFieldParam('title.raw', 'slop', 3);`
    `$matchPhrase->setFieldBoost('title.raw', 10);`
    `$bq->addShould($matchPhrase);`
 }

Solution

  • yes you can boost a field like:

        [...]
        types:
            autor:
                properties:
                    orig_id:
                        type: "integer"
                        property_path: origId
                        boost: 10
    

    see https://github.com/FriendsOfSymfony/FOSElasticaBundle/blob/master/doc/indexes.md#nested-objects-in-foselasticabundle