小编Cpt*_*nch的帖子

Elasticsearch 过滤嵌套对象

我有一个简化的对象,看起来像这样:

"name" : "Partner Name",
"features" : [ 
    {
        "val" : "Family",
        "key" : "Type"
    },
    {
        "val" : "Paris",
        "key" : "City"
    }
],
"variants" : [ 
    {
        "name" : "Activity 1 Name",
        "description" : "Quick description",
        "price" : 20
    }
]
Run Code Online (Sandbox Code Playgroud)

我想按“城市”和“类型”键进行过滤。我当前的查询按价格过滤,但无法使其适用于城市或类型。向过滤器数组添加更多项并没有达到目的。

'query':{
    'filtered':{
        'query':{
            'query_string':{
                'query':query
            }
        },
    'filter': {
        'bool':{
            'filter': [{ 
                    'range': {
                        'variants.price': {
                            'gte': 0
                        }
                    }
                },
                { 
                    'range': {
                        'variants.price': {
                            'lte': 50
                        }
                    }
                },
                {
                    'term': {
                        'active': true …
Run Code Online (Sandbox Code Playgroud)

json elasticsearch

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

elasticsearch ×1

json ×1