【发布时间】:2015-02-26 14:11:44
【问题描述】:
我正在尝试用 elasticsearch 制作一种 group_by。
我存储一个文本字段:
"text": {
"type": "string",
"store": true,
"analyzer" : "twittsTokenizor"
},
还有一个地理品脱字段
"geo": {
"type": "geo_point",
"store": true
}
我正在尝试获取按我所在位置分组的文本字段中最常用的术语,但它不起作用。
如果这样的查询有效(如果我在查询中定义了我的位置):
curl -XGET http://localhost:9200/twitter/_search -d '{
"query" : {
"match_all" : {}
},
"filter" : {
"bool" : {
"must" : [{
"range" : {
"created_at" : {
"from" : "Mon Feb 22 14:04:23 +0000 2015",
"to" : "Wed Feb 23 22:06:25 +0000 2015"
}}
},{
"geo_distance" : {
"distance" : "100km",
"geo" : { "lat" : 48.856506, "lon" : 2.352133 }
}}
]
}
},
"facets" : {
"tag" : {
"terms" : {
"field" : "text" ,
"size" : 10
}
}
}
}'
这不起作用:
curl -XGET http://localhost:9200/twitter/_search -d '{
"query" : {
"match_all" : {
}
},
"aggs" : {
"geo1" : {
"terms" : {
"field" : "geo"
}
},
"tag" : {
"terms" : {
"field" : "text" ,
"size" : 10
}
}
}
}
}'
这不起作用:
curl -XGET http://localhost:9200/twitter/_search -d '{
"query" : {
"match_all" : {
}
},
"facets" : {
"tag" : {
"terms" : {
"field" : "text" ,
"size" : 10
}
},
"geo1" : {
"terms" : {
"field" : "geo"
}
}
}
}
}'
而 facet_filters 没有完成这项工作。
我做错了什么?甚至可能吗? 非常感谢。
编辑:这是我的映射:
curl -s -XPUT "http://localhost:9200/twitter" -d '
{
"settings": {
"analysis": {
"analyzer": {
"twittsTokenizor" : {
"type" : "custom",
"tokenizer" : "standard",
"filter" : [
"french_elision",
"asciifolding",
"lowercase",
"french_stop",
"english_stop",
"twitter_stop"
]
}
},
"filter" : {
"french_elision" : {
"type" : "elision",
"articles" : [ "l", "m", "t", "qu", "n", "s",
"j", "d", "c", "jusqu", "quoiqu",
"lorsqu", "puisqu"
]
},
"asciifolding" : {
"type" : "asciifolding"
},
"french_stop": {
"type": "stop",
"stopwords": "_french_"
},
"english_stop": {
"type": "stop",
"stopwords": "_english_"
},
"twitter_stop" : {
"type" : "stop",
"stopwords": ["RT", "FAV", "TT", "FF", "rt"]
}
}
}
},
"mappings": {
"twitter": {
"properties": {
"id": {
"type": "long",
"store": true
},
"text": {
"type": "string",
"store": true,
"analyzer" : "twittsTokenizor"
},
"created_at": {
"type": "date",
"format": "EE MMM d HH:mm:ss Z yyyy",
"store": true
},
"location": {
"type": "string",
"store": true
},
"geo": {
"type": "geo_point",
"store": true
}
}
}
}
}'
和数据样本:
{ "_id" : ObjectId("54eb3c35a710901a698b4567"), "country" : "FR", "created_at" : "Mon Feb 23 14:25:30 +0000 2015", "geo" : { "lat" : 49.119696, "lon" : 6.176355 }, "id" : -812216320, "location" : "Metz ", "text" : "Passer des vacances formidable avec des gens géniaux sans aucunes pression avec pour seul soucis s'éclater et se laisser vivre #BONHEUR"}
【问题讨论】:
-
此外,您可以将相同的数据存储在字符串字段中(而不是 geo_point 类型),因此您可以使用术语聚合。
标签: elasticsearch facet