FOS Elastica double nested not_match with no results

EAV – product model
I’m making a smart filter and I’m done with everything.
But not all values need to be counted, such as width, height, depth.
And that’s exactly what I can’t do

Here’s my config:

fos_elastica:
clients:
    default: { url: '%env(ELASTICSEARCH_URL)%' }
indexes:
    product:
           properties:
               unitPrice:
                   type: integer
               discount:
                   type: keyword
               attributeValues:
                   type: "nested"
                   properties:
                       value:
                           type: keyword
                       product:
                           type: keyword
                       attributeType:
                           type: "nested"
                           properties:
                               name:
                                   type: keyword
           persistence:
               driver: orm
               model: AppEntityProduct
               provider: ~
               listener: ~
               finder: ~

Here is the working part of the request:

        $query = new ElasticaQuery();
    $query->setSize(0);

    $boolQuery = new ElasticaQueryBoolQuery();

  /* filter checked */
    $fieldQuery = new ElasticaQueryMatch();
    $fieldQuery->setFieldQuery('attributeValues.value', 'Brand');
    $domainQuery = new ElasticaQueryNested();
    $domainQuery->setPath('attributeValues');
    $domainQuery->setQuery($fieldQuery);

    $fieldQuery2 = new ElasticaQueryMatch();
    $fieldQuery2->setFieldQuery('attributeValues.value', 'Another Brand');
    $domainQuery2 = new ElasticaQueryNested();
    $domainQuery2->setPath('attributeValues');
    $domainQuery2->setQuery($fieldQuery2);

    $fieldRange = new ElasticaQueryRange('unitPrice', array('gte' => 300, 'lte' => 1500));


    $boolQuery->addMust($domainQuery);
    $boolQuery->addMust($domainQuery2);
    $boolQuery->addMust($fieldRange);

    $query->setQuery($boolQuery);

    $agg = new ElasticaAggregationNested('attributeValues', 'attributeValues');
    $names = new ElasticaAggregationTerms('value');
    $cardinality = new ElasticaAggregationCardinality('unique_products');

    $cardinality->setField('attributeValues.product');
    $names->setField('attributeValues.value');
    $names->setSize(100);

    $names->addAggregation($cardinality);
    $agg->addAggregation($names);
    $query->addAggregation($agg);


    $companies = $this->finder->findPaginated($query);
    $asd = $companies->getAdapter()->getAggregations();

here is a short version of the result:

        array(
        "attributeValues" => array:2(
            "doc_count" => 630,
            "value" => array:3(
                "doc_count_error_upper_bound" => 0,
                "sum_other_doc_count" => 0,
                "buckets" => array:42(
                    "key" => "Brand",
                    "doc_count" => 22,
                    "unique_products" => array:1(
                        "value" => 20
                    )
                )
            )
        )
    );

But when I add this, I get 0 results

        $fieldWidth = new ElasticaQueryMatch();
    $fieldWidth->setFieldQuery('attributeValues.attributeType.name', 'width');
    $domainWidth = new ElasticaQueryNested();
    $domainWidth->setPath('attributeValues.attributeType');
    /* double nested try
    $domainWidthSub = new ElasticaQueryNested();
    $domainWidthSub->setPath('attributeValues.attributeType');
    $domainWidthSub->setQuery($fieldWidth);
    $domainWidth->setQuery($domainWidthSub);
    */
    $domainWidth->setQuery($fieldWidth);
    $boolQuery->addMustNot($domainWidth);

raw query looks like this: (just in case)

{
"size": 0,
"query": {
    "bool": {
        "must": [
            {
                "nested": {
                    "path": "attributeValues",
                    "query": {
                        "match": {
                            "attributeValues.value": {
                                "query": "Brand"
                            }
                        }
                    }
                }
            },
            {
                "nested": {
                    "path": "attributeValues",
                    "query": {
                        "match": {
                            "attributeValues.value": {
                                "query": "Another Brand"
                            }
                        }
                    }
                }
            },
            {
                "range": {
                    "unitPrice": {
                        "gte": 300,
                        "lte": 1500
                    }
                }
            }
        ],
        "must_not": [
            {
                "nested": {
                    "path": "attributeValues.attributeType",
                    "query": {
                        "match": {
                            "attributeValues.attributeType.name": {
                                "query": "width"
                            }
                        }
                    }
                }
            }
        ]
    }
},
"aggs": {
    "attributeValues": {
        "nested": {
            "path": "attributeValues"
        },
        "aggs": {
            "value": {
                "terms": {
                    "field": "attributeValues.value",
                    "size": 100
                },
                "aggs": {
                    "unique_products": {
                        "cardinality": {
                            "field": "attributeValues.product"
                        }
                    }
                }
            }
        }
    }
}

}

any ideas what the problem is? I would be grateful for any advice

Source: Symfony4 Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *