【发布时间】: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