massiveart / MassiveSearchBundle

MIT License
67 stars 24 forks source link

Take indexed argument into account when using ElasticSearchAdapter #160

Open fnordo opened 2 years ago

fnordo commented 2 years ago

In use with Sulu v2.3.3, i tried to add an additional, non-searchable field to an index by listening to the PreIndexEvent and adding the field manually using Massive\Bundle\SearchBundle\Search\Factory\Factory like so:

        $document->addField($this->factory->createField(
            'my_additional_field',
            $value,
            Field::TYPE_STRING,
            true,
            false
        ));

Although the $indexed-param of $factory::createField() is set to false, the additionally created field is still searchable within the index.

According to feedback on this topic in the Sulu Slack Channel, the root of the problem is to be found in ElasticSearchAdapter::prepareSearch(SearchQuery $searchQuery), as the query_string-array should contain an additional fields array containing the names of all fields where $indexed is true.