【问题标题】:elastic search aggregation field doesn't work..?弹性搜索聚合字段不起作用..?
【发布时间】:2016-12-26 11:01:00
【问题描述】:

我正在使用 elasticsearch python API 在 elasticsearch 索引上索引 JSON 对象。

我无法通过文档后的多令牌字段获得预期结果。

我在下面提供我的身体映射代码:

body={"mappings":{
        "my_doc": {
            "properties": {
                "id": {
                    "properties": {
                        "name": {"type": "string"},
                        "value": {"type": "keyword"}
                    }
                },
                "name": {
                    "properties": {
                        "first": {"type": "text"},
                        "last": {"type": "text"}
                    }
                },
                "location": {
                    "properties": {
                        "city": {"type": "text"},
                        "state": {
                                "type": "text",
                                "fielddata": True,
                                "fields": {
                                    "raw": {
                                        "type": "string",
                                        "index": "not_analyzed"
                                    }
                                }
                        },
                        "street": {"type": "text"},
                        "postcode": {"type": "text"}
                    }
                }
            }
        }
    }
}

当我使用这个 aqg 查询时:

curl -XGET localhost:9200/my_index/_search -d '{
"size": 0,
"aggs": {
    "locations": {
        "terms": {
            "field": "location.state"
        }
    }
  }
}'

我获得令牌,好的 但是,当我使用原始字段时:

curl -XGET localhost:9200/my_index/_search -d '{
"size": 0,
"aggs": {
    "locations": {
        "terms": {
            "field": "location.state.raw"
        }
    }
  }
}'

我没有得到桶。

有什么建议吗?

遵循 Lax 建议的最终映射:

body={"mappings":{
            "my_doc": {
                "properties": {
                    "id": {
                        "properties": {
                            "name": {"type": "string"},
                            "value": {"type": "keyword"}
                        }
                    },
                    "name": {
                        "properties": {
                            "first": {"type": "text"},
                            "last": {"type": "text"}
                        }
                    },
                    "location": {
                        "properties": {
                            "city": {"type": "text"},
                            "state": {
                                    "type": "text",
                                    "fields": {
                                        "keyword": {
                                            "type": "keyword"
                                        }
                                    }
                            },
                            "street": {"type": "text"},
                            "postcode": {"type": "text"}
                        }
                    }
                }
            }
        }
    }

【问题讨论】:

    标签: python elasticsearch


    【解决方案1】:

    在那个映射中删除

    "index": "not_analyzed
    

    它会起作用的

    【讨论】:

    • 对不起,我继续:{"error":{"root_cause":[{"type":"illegal_argument_exception","re​​ason":"默认情况下在文本字段上禁用字段数据。设置 fielddata=true在 [location.state.raw] 上,以便通过反转倒排索引将字段数据加载到内存中。注意 ...
    • 阅读下一个链接elastic.co/guide/en/elasticsearch/reference/current/…对你很有用。如果您有任何问题,请随时提出
    • 谢谢松懈!!。按照链接解决。
    猜你喜欢
    • 2015-02-16
    • 1970-01-01
    • 2015-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多