Optional self-rotate in Elasticsearch

I have a Symfony2 project, and I'm trying to implement a search function using Elasticsearch.

My problem: I need to index an entity with optional dedication. This means that my Item object has a parent field that refers to another element.

To perform a search, I want to create filters in this "parent" field. Is my Item.parent NULL? eg.

So, I am using FosElasticaBundle.

Here is my mapping:

    types:
    Item:
        mappings:
            name:
            children:
                type: object
                _parent:
                    type: Item
            parent:
                type: object
        _routing:
            required: false
        _parent:
            type : Item
            identifier: id
            property : parent
        persistence:
            ...
            model_to_elastica_transformer:
                service: core.transformer.item

And the transformer does:

$document = new Document();

if (!is_null($item->getParent())) {
    $document->setParent($item->getParent()->getId());
} else {
     $document->setParent(null);
}

return $document;

And the problem occurs when I try to create my index ( php app/console fos:elastica:populate)

This command returns the following ResponseException:

index: /traveler/Item caused RoutingMissingException[routing is required for [traveler]/[Item]/[null]] 

Do you have an idea why this is not working? And is this a good way to do this?

Thanks,

+4
1

, .

_parent config .

Item:
    mappings:
        children:
            type: "nested"
            properties:
                name: ~
        parent:
            type: "object"

, - Item. requess ( null, -...)

, \Elasitca\Filter\Nested.

, , :

$nestedFilter  = new Nested();
$boolFilter    = new Bool();
$boolAndFilter = new BoolAnd();
$boolAndFilter
    ->setFilters(array(
        new Term(array("children.user.id" => $this->getClient()->getId())),
        new Term(array("children.other" => $language))
    ))
;

$nestedFilter
    ->setFilter($boolAndFilter)
    ->setPath('children')
;

$query = new Filtered(
    $query,
    new BoolNot($boolFilter->addMust($nestedFilter))
);

, ( ), .

+1

Source: https://habr.com/ru/post/1627950/


All Articles