P
P
P7472020-10-21 15:04:18
css
P747, 2020-10-21 15:04:18

Yii & elasticsearch match on multiple parameters?

Good afternoon!

How to execute query by name (name) and exact match to parameter (parent_id) with null? Right now I'm trying to run the following queries:

query(
                [
                    'bool' => [
                        'should' => [
                            ['match' => ['name' => '{ИМЯ}']],
                        ],
                        'must' => [
                            ['term' => ['type' => '{ТИП}']]
                        ]
                    ]
                ]
            )
//Выводит значения которые совпадают или по "name" или "type"

query(
                [
                    'bool' => [
                        'should' => [
                            ['match' => ['name' => '{ИМЯ}']],
                        ],
                        'must' => [
                            ['term' => ['parent_id' => null]]
                        ]
                    ]
                ]
            )

//Выдает ошибку поиска, но нужно чтобы искал по совпадению "name" и точному "parent_id == null"

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
Chvalov, 2016-04-01
@fredaev

Vod so: codepen.io/thetwistedtaste/pen/GgrWLp
codepen.io/MarcoGuglielmelli/pen/lLCxy
http://ru.stackoverflow.com/questions/456861/Anima...
+ To the same opera stackoverflow.com/questions/ 30965226/meteor-js-load...

P
P747, 2020-10-22
@P747

Understood, the request will be like this:

query(
    [
        'bool' => [
            'must' => [
                'query_string' => ['default_field' => 'name', 'query' => "*$text*"]
            ],
            'must_not' => [
                'exists' => [
                    'field' => 'parent_id',
                ]
            ]
        ]
    ]
)
//Для поиска "нечеткому" значению "name" и нулевого "parent_id"

query(
    [
        'bool' => [
            'must' => [
                ['query_string' => ['default_field' => 'name', 'query' => "*$text*"]],
                ['term' => ['parent_id' => $parentId]],
            ]
        ]
    ]
)
//Для поиска "нечеткому" значению "name" и значению "parent_id"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question