由于 kibana3 中,并不支持直接在请求的 url 中设置搜索的 type 。
为了支持 type 的搜索,所以我设置了个下每个 panel 的查询语句,让它增加一个:
"query_string":
{"query": " _type:\"my_type\" "}
结果今天在查一个 bug 的时候,发现这样有一个坑,,,
由于URL请求的路径并没有给出 type ,所以每一次的搜索,依然会查询整个 index,只是在获取结果时候,再过滤一次 type 字段。
如果在同一个 index 下,存在不同 type 中,某个字段类型不一致的情况,那将可能导致搜索不到想要的结果。(因为不同的 type 有不同的 _mapping)
比如:
我在一个字段第一次存的时候,存为了 string 类型,而又新建了另一个 type,且类型变为了 date,
后来在对这个字段进行时间过滤的时候,发现总是不生效,hits 总是空,
URL:http://localhost:9200/index/_search { "query": { "filtered": { "query": { "bool": { "should": [{ "query_string": { "query": "_type:\"my_type\"" } }] } }, "filter": { "bool": { "must": [{ "range": { "过期时间": { "from": 1860000665, "to": 2550091665 } } }] } } } }, "from": 0 }
结果:
{ "took": 1, "timed_out": false, "_shards": { "total": 1, "successful": 1, "failed": 0 }, "hits": { "total": 0, "max_score": 1, "hits": [] ......
但是,完全相同的查询语句,如果在 URL 中指定 type,那么过滤就 OK 了,,,
URL: http://200.200.194.155:9200/index/my_type/_search { "query": { "filtered": { "query": { "bool": { "should": [{ "query_string": { "query": "_type:\"my_type1\"" } }] } }, "filter": { "bool": { "must": [{ "range": { "过期时间": { "from": 1861665, "to": 25500008799861665 } } }] } } } }, "from": 0 }
结果:
{ "took": 1, "timed_out": false, "_shards": { "total": 1, "successful": 1, "failed": 0 }, "hits": { "total": 67, "max_score": 1, "hits": [ { ......
确保相同字段的数据类型一致,,,so,删掉某一些,,,只保留一个呗。
或者,最好是能够设置请求的 URL 吧,把 type 加到请求的路径中去。
原文:http://www.cnblogs.com/licongyu/p/5315700.html