我遇到了Elasticsearch Term Facet
的问题我把数据如下:
curl -X DELETE "http://localhost:9200/articles'
curl -X POST "http://localhost:9200/articles/article" -d '{"title" : "One", "tags" : "foo","datetime":"2005-12-23 23:10:52"}'
curl -X POST "http://localhost:9200/articles/article" -d '{"title" : "Two", "tags" : "bar","datetime":"2005-12-23 23:10:53"}'
curl -X POST "http://localhost:9200/articles/article" -d '{"title" : "Three", "tags" : "baz","datetime":"2005-12-23 23:10:54"}'
curl -X POST "http://localhost:9200/articles/article" -d '{"title" : "four", "tags" : "baz","datetime":"2005-12-23 23:10:55"}'
curl -X POST "http://localhost:9200/articles/article" -d '{"title" : "five", "tags" : "foo","datetime":"2005-12-23 23:10:56"}'
所以每当我查询术语时,它都会给出正确的结果,以下是我的Elasticsearch查询:
curl 'http://localhost:9200/articles/article/_search?pretty=true' -d '{
"query": {
"match_all": {}
},
"facets" : { "myfacet" : { "terms" : {"field" : "tags"}}
}
}'
但是,当我向Facet添加过滤器时,它将不会显示以下任何方面计数:
curl 'http://localhost:9200/articles/article/_search?pretty=true' -d '{
"query": {
"match_all": {}
},
"facets" : {
"myfacet" : { "terms" : {"field" : "tags"},
"filter" : { "range" :{
"datetime" : {"from" : "2005-12-23 3:10:52","to" : "2005-12-23 23:10:56" }
}
}
}
}
}'
我得到如下结果
facets" : {
"myfacet" : {
"_type" : "filter",
"count" : 0
}
}
所以,任何人都知道为什么要给予这样的计数。
答案 0 :(得分:1)
日期格式无效,请查看elasticsearch支持的支持日期时间格式(太长,请勿阅读,弹性搜索支持jodatime支持的任何日期)。
http://www.elasticsearch.org/guide/reference/mapping/date-format.html
话虽如此,您只需在insert语句中修改日期并将其置于有效的日期格式中,例如2005-12-23T23:10:55Z
。然后只需将查询更改为该时间格式的正确时间范围,这应该会给您结果。
编写这些查询时也要小心,因为我注意到你在from子句中使用的日期无效。
以下是修改过的curl脚本:
curl -X POST "http://localhost:9200/articles/article" -d '{"title" : "One", "tags" : "foo","datetime":"2005-12-23T23:10:52Z"}'
curl -X POST "http://localhost:9200/articles/article" -d '{"title" : "Two", "tags" : "bar","datetime":"2005-12-23T23:10:53Z"}'
curl -X POST "http://localhost:9200/articles/article" -d '{"title" : "Three", "tags" : "baz","datetime":"2005-12-23T23:10:54Z"}'
curl -X POST "http://localhost:9200/articles/article" -d '{"title" : "four", "tags" : "baz","datetime":"2005-12-23T23:10:55Z"}'
curl -X POST "http://localhost:9200/articles/article" -d '{"title" : "five", "tags" : "foo","datetime":"2005-12-23T23:10:56Z"}'
和修改过的搜索:
curl 'http://localhost:9200/articles/article/_search?pretty=true' -d '{
"query": {
"match_all": {}
},
"facets" : {
"myfacet" : {
"terms" : {"field" : "tags"},
"filter" : { "range" :{
"datetime" : {
"from" : "2005-12-23T23:10:52Z",
"to" : "2005-12-23T23:10:54Z"
}
}
}
}
}
}'
希望这有帮助, 马特