我使用的是elasticsearch 2.1。我不太清楚我做错了什么。令我感到困惑的是查询,过滤器之间的差异......你能帮帮我吗?
我试图执行此查询。它返回一个空结果:
curl -XGET 'http://ESNode01:9201/living_team/inputs/_search?pretty' -d '
{
"query": {
"filtered": {
"query": { "match_all": {} },
"filter": { "term": { "channel": "Feina" } }
}
}
}
'
但是,当我在没有过滤器的情况下执行此查询时,它会返回所有内容:
curl -XGET 'http://ESNode01:9201/living_team/inputs/_search?pretty' -d '
{
"query": {
"filtered": {
"query": { "match_all": {} },
}
}
}
'
这是一份文件样本:
{
"user":"living_team",
"timestamp":"2015-12-14T18:06:47.085Z",
"matter":"snip2.PNG",
"comment":"Archive",
"channel":"Feina",
"feedTypes":[
20
],
"property_general_ldate":"2015-12-14T18:06:47.085Z",
"property_tSize":7595.0,
"resources":[
{
"timestamp":"2015-12-14T16:58:00.598Z",
"matter":"snip2.PNG",
"comment":"Archive",
"channel":"Feina",
"feedType":20,
"mime":"image/png",
"source":{
"sourceId":{
"id":"C:\\Users\\Beep\\Desktop\\share\\snip2.PNG",
"batch":"c38eec2d-a282-11e5-baf4-382c4ab9e433",
"client":"VIM12HCNZL"
},
"feedType":20,
"property_folder":"C:\\Users\\Beep\\Desktop\\share",
"property_lastAccessFolder_ldate":1450111821506
},
"property_size":7595.0,
"property_creation_ldate":"2015-12-14T16:50:20.578Z",
"property_name":"snip2.PNG",
"nestedResources":[
]
}
]
答案 0 :(得分:2)
您的channel
字段可能是analyzed
,因此它被编入索引为小写字符串。以下查询将起作用(即使用feina
小写):
curl -XGET 'http://ESNode01:9201/living_team/inputs/_search?pretty' -d '
{
"query": {
"filtered": {
"query": { "match_all": {} },
"filter": { "term": { "channel": "feina" } }
}
}
}
'
另一种解决方案是在您的地图中将channel
字段设为not_analyzed
字符串,并将term
过滤器与Feina
一起使用(但不能与feina
一起使用了)。最后,它取决于您希望如何存储和搜索数据。
答案 1 :(得分:1)
这应该有用。
curl - XGET 'http://ESNode01:9201/living_team/inputs/_search?pretty' - d ' {
{
"query": {"match": {
"channel": "feina" }}
}'