Nosql Elasticsearch的意外结果
我有一些文件存储在ES中(通过日志存储)。查询ES时,结果看起来不正确: 第一个查询(参见下面的查询和结果)假定(意味着)只返回不包含Nosql Elasticsearch的意外结果,nosql,elasticsearch,logstash,Nosql,elasticsearch,Logstash,我有一些文件存储在ES中(通过日志存储)。查询ES时,结果看起来不正确: 第一个查询(参见下面的查询和结果)假定(意味着)只返回不包含区域字段的文档 更进一步,根据第一次查询的结果,显然有一个文档包含字段region,但是,第二次查询的结果(至少)应该返回一个region=IN的文档,而不包含任何文档 我的问题有问题吗 我如何调查问题所在?(ES日志没有任何与这些查询相关的内容) 以下是查询: curl -X GET 'http://localhost:9200/logstash*/_sea
区域
字段的文档
更进一步,根据第一次查询的结果,显然有一个文档包含字段region
,但是,第二次查询的结果(至少)应该返回一个region=IN
的文档,而不包含任何文档
- 我的问题有问题吗
- 我如何调查问题所在?(ES日志没有任何与这些查询相关的内容)
curl -X GET 'http://localhost:9200/logstash*/_search?pretty' -d '{
"query" : {
"match_all" : {}
},
filter : {
"and" : [
{ "term" : { "type" : "xsys" } },
{ "missing" : { "field" : "region" } }
]
}, size: 2
}'
结果是:
{
"took" : 40,
"timed_out" : false,
"_shards" : {
"total" : 90,
"successful" : 90,
"failed" : 0
},
"hits" : {
"total" : 5747,
"max_score" : 1.0,
"hits" : [ {
"_index" : "logstash-2013.09.28",
"_type" : "logs",
"_id" : "UMrz9bwKQgCq__TwBT0WmQ",
"_score" : 1.0,
"_source" : {
.....
"type":"xsys",
....
"region":"IN",
}
}, { ....
} ]
}
}
此外,以下查询的结果:
curl -X GET 'http://localhost:9200/logstash*/_search?pretty' -d '{
"query" : { "match_all" : {} },
filter : { "term" : { "region" : "IN" } },
size: 1
}'
是:
使用以下映射:
curl -XPUT http://localhost:9200/_template/logstash_per_index -d '
{
"template": "logstash*",
"settings": {
"index.query.default_field": "message",
"index.cache.field.type": "soft",
"index.store.compress.stored": true
},
"mappings": {
"_default_": {
"_all": { "enabled": false },
"properties": {
"message": { "type": "string", "index": "analyzed" },
"@version": { "type": "string", "index": "not_analyzed" },
"@timestamp": { "type": "date", "index": "not_analyzed" },
"type": { "type": "string", "index": "not_analyzed" },
....
"region": { "type": "string", "index": "not_analyzed" },
...
}
}
}
}'
映射(ES返回的内容-curl-XGET'http://localhost:9200/logstash-2013.09.28/_映射
):
是否对字段区域进行索引?你能发布你的映射吗?@javanna我已经在第二次查询中添加了映射,如果我使用
match
而不是term
,我会得到结果。是的,很好,恐怕你在模板中的默认映射没有得到应用,因此区域字段被分析(小写)。您将使用术语过滤器获得结果,但在小写中查询。你能确认吗?不,即使是
中的小写也不起作用。但是,如果我使用us
(我有us
的文档),我会得到结果。
curl -XPUT http://localhost:9200/_template/logstash_per_index -d '
{
"template": "logstash*",
"settings": {
"index.query.default_field": "message",
"index.cache.field.type": "soft",
"index.store.compress.stored": true
},
"mappings": {
"_default_": {
"_all": { "enabled": false },
"properties": {
"message": { "type": "string", "index": "analyzed" },
"@version": { "type": "string", "index": "not_analyzed" },
"@timestamp": { "type": "date", "index": "not_analyzed" },
"type": { "type": "string", "index": "not_analyzed" },
....
"region": { "type": "string", "index": "not_analyzed" },
...
}
}
}
}'
{
"logstash-2013.09.28":{
"logs":{
"_all":{
"enabled":false
},
"properties":{
"@timestamp":{
"type":"date",
"format":"dateOptionalTime"
},
"@version":{
"type":"string",
"index":"not_analyzed",
"omit_norms":true,
"index_options":"docs"
},
"message":{
"type":"string"
},
"region":{
"type":"string"
},
"type":{
"type":"string",
"index":"not_analyzed",
"omit_norms":true,
"index_options":"docs"
}
}
},
"_default_":{
"_all":{
"enabled":false
},
"properties":{
"@timestamp":{
"type":"date",
"format":"dateOptionalTime"
},
"@version":{
"type":"string",
"index":"not_analyzed",
"omit_norms":true,
"index_options":"docs"
},
"message":{
"type":"string"
},
"type":{
"type":"string",
"index":"not_analyzed",
"omit_norms":true,
"index_options":"docs"
}
}
}
}
}