【问题标题】:Elasticsearch migration filterElasticsearch 迁移过滤器
【发布时间】:2017-11-07 16:54:11
【问题描述】:

这是我的问题:我需要将过滤器/查询语法 (elasticsearch 1.x) 转换为 elasticsearch 5.x 语法。

这是我的查询:

{
"query ": {
    "filtered ": {
        "query ": {
            "fuzzy_like_this ": {
                "like_text ": "    cin ",
                "max_query_terms ": 12,
                "fuzziness ": 0.7
            }
        },
        "filter ": {
            "and ": {
                "filters ": [{
                    "or ": {
                        "filters ": [{
                            "type ": {
                                "value ": "etude_patrimoine_architecture "
                            }
                        }]
                    }
                }]
            }
        }
    }
}
}

我不太了解弹性 5.x 的 bool 语法。

任何帮助迁移此过滤器将不胜感激。

【问题讨论】:

    标签: json elasticsearch filter filtering elasticsearch-5


    【解决方案1】:

    基本上,

    • filtered/query 部分进入bool/must
    • filtered/filter 部分位于 bool/filterbool/must_notbool/should 中,具体取决于您是否需要 AND、NOT 或 OR 行为。

    这样的事情应该可以帮助您入门:

    {
      "query": {
        "bool": {
          "must": [
             query
          ],
          "should": [
             queryLayers
          ]
        }
      }
    }
    

    【讨论】:

    • 谢谢 Val,我会试试你的解决方案。我已经更新了我的帖子,以便使用 json stringify 更加清晰。
    【解决方案2】:

    这是最终的解决方案:

    {
        "query": {
            "bool": {
                "must": [{
                    "match": {
                        "_all": {
                            "query": QUERYVALUE,
                            "fuzziness": "AUTO"
                        }
                    }
                }, {
                    "bool": {
                        "should": [{
                            "type": {
                                "value": VAL1
                            }
                        }, {
                            "type": {
                                "value": VAL2
                            }
                        }]
                    }
                }],
                "filter": {
                    "geo_shape": {
                        "geometry": {
                            "shape": {
                                "type": "envelope",
                                "coordinates": COORDARAY
                            }
                        }
                    }
                }
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-31
      • 2017-06-24
      • 2017-08-29
      相关资源
      最近更新 更多