Yii2 and nested objects

Hi. I'm totally new in ElasticSearch. I'm using "Yii2 Framework" and stalked on. Elastic not works with nested field. Is here specialist in Yii2 & Elasticsearch? Or where I can find the answer? Documents in index are like this:

{
  "id" : 28,
  "name" : "Futura Door",
  "description" : "Futura Door",
  "code" : "7339",
  "price" : 14924,
  "values" : {
    "type" : "nested",
    "properties" : [
      {
        "characteristic" : 1,
        "value_string" : "Grey",
        "value_int" : 0
      },
      {
        "characteristic" : 2,
        "value_string" : "Futura",
        "value_int" : 0
      }
    ]
  }
}

Query is made with framework like this:

    'query' => [
        'bool' => [
            'must' => array_merge(
                array_filter([
                    !empty($form->text) ? ['multi_match' => [
                        'query' => $form->text,
                        'fields' => ['name^2', 'description']
                    ]] : false,
                ]),
                array_map(function (Value $value) {
                    return ['nested' => [
                        'path' => 'values',
                        'query' => [
                            'bool' => [
                                'must' => array_filter([
                                    ['match' => ['values.characteristics' => $value->getId()]],
                                    !empty($value->equal) ? ['match' => ['values.value_string' => $value->equal]] : false,
                                    !empty($value->from) ? ['range' => ['values.value_int' => ['gte' => $value->from]]] : false,
                                    !empty($value->to) ? ['range' => ['values.value_int' => ['lte' => $value->to]]] : false,
                                ]),
                            ],
                        ],
                    ]];
                }, array_filter($form->values, function (ValueForm $value) {
                    return $value->isFilled();
                }))
            )
        ],
    ],

Decision were very simple. I had to add path 'product' before values

array_map(function (ValueForm $value) {
                                        return [
                                            'nested' => [
                                                'path' => 'product.values',
                                                'query' => [
                                                    'bool' => [
                                                        'must' => array_filter([
                                                            ['match' => ['product.values.characteristic' => $value->getId()]],
                                                            !empty($value->equal) ? ['match' => ['product.values.value_string' => $value->equal]] : false,
                                                            !empty($value->from) ? ['range' => ['product.values.value_int' => ['gte' => $value->from]]] : false,
                                                            !empty($value->to) ? ['range' => ['product.values.value_int' => ['lte' => $value->to]]] : false,
                                                        ]),
                                                    ],
                                                ],
                                            ]];
                                    }, array_filter($form->values, function (ValueForm $value) {
                                        return $value->isFilled();
                                    })),

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.