0

我需要将 OLD 查询从 ES2.0 转换为 ES6.1 ......这似乎并不容易......原来的查询是:

{
    "size":0,
    "query": {
        "bool": {
            "filter": {
                "bool": {
                    "must": {
                        "query": {
                            "match": {
                                "my_hits": {
                                    "query": 0,
                                    "type": "phrase"
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "fields": "ip",
    "aggregations": {
        "par_ip": {
            "terms": {
                "field": "ip",
                "min_doc_count": 2,
                "size": 10000,
                "order": {
                    "_term": "asc"
                }
            }
        }
    }
}

我认为第一部分可以转换为:

{
 "size": 0,
 "query": {
    "match" : {
        "my_hits": "0"
    }
  }
}

但其余的我被困住了......

"type": "illegal_argument_exception", "reason": "默认情况下,文本字段上的字段数据是禁用的。在 [ip] 上设置 fielddata=true 以便通过反转倒排索引将字段数据加载到内存中。请注意,这可能会使用显着记忆。或者使用关键字字段。

编辑:我认为您将需要这些信息:

"mappings": { ... "ip": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } },

谢谢你的帮助 !斯蒂芬妮

4

1 回答 1

0

如果要保留不考虑评分的过滤子句,因此没有结果排序控制,一种可能的翻译是:

{
    "size":0,
    "query": {
        "bool": {
            "filter": {
              "match_phrase": {
                "my_hits": "some query"
              }
          }
        }
    },
    "stored_fields": "ip",
    "aggregations": {
        "par_ip": {
            "terms": {
                "field": "ip",
                "min_doc_count": 2,
                "size": 10000,
                "order": {
                    "_term": "asc"
                }
            }
        }
    }
}

这里也将fields字段更改为stored_fieldsmatch类型phrase为查询的查询现在是match_phrase查询。如果您希望查询影响结果的分数,则应避免使用以下filter子句:

{
    "size":0,
    "query": {
       "match_phrase": {
          "my_hits": "some query"
       }
    },
    "stored_fields": "ip",
    "aggregations": {
        "par_ip": {
            "terms": {
                "field": "ip",
                "min_doc_count": 2,
                "size": 10000,
                "order": {
                    "_term": "asc"
                }
            }
        }
    }
}

如果要将其检索为映射,则必须将该ip字段标记为存储在映射中"store": truestored_field

于 2018-02-02T12:12:29.133 回答