Elastic Search not returning matched data
我有一个弹性搜索索引,映射如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | { "issues": { "mappings": { "issues": { "properties": { "captured_by": { "type":"long" }, "captured_on": { "type":"date", "format":"dateOptionalTime" }, "description": { "type":"string" }, "id": { "type":"string", "index":"not_analyzed" }, "updated_at": { "type":"date", "format":"dateOptionalTime" } "issue_org_states": { "type":"nested", "properties": { "assigned_at": { "type":"date", "format":"dateOptionalTime" }, "assigned_by": { "type":"long" }, "updated_at": { "type":"date", "format":"dateOptionalTime" }, "updated_by": { "type":"long" } } } } } } } } |
并填充一个文档如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | { "took": 2, "timed_out": false, "_shards": { "total": 1, "successful": 1, "failed": 0 }, "hits": { "total": 1, "max_score": 1, "hits": [ { "_index":"issues", "_type":"issues", "_id":"13f3bf09-08cb-4464-b326-15872bdb0870", "_score": 1, "_source": { "id":"13f3bf09-08cb-4464-b326-15872bdb0870", "description":"Sloppy paint job", "captured_on":"2017-10-09T09:24:01.928Z", "captured_by": 1, "updated_at":"2017-10-09T12:47:22.982Z", "issue_org_states": [ { "updated_at":"2017-10-09T12:47:22.982Z", "updated_by": 1, "assigned_at":"2017-10-09T12:47:22.982Z", "assigned_by": 1879048240 } ] } } ] } } |
我想查询属性assigned_at 和updated_at 上的路径"issues.issue_org_states"。
查询如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | { "query": { "nested": { "path":"issue_org_states", "range": { "assigned_at": { "from":"2017-10-09T00:00:00.000Z", "to":"2017-10-09T23:59:59.999Z", "include_lower": true, "include_upper": true } } } } } |
当我在上面运行时查询它的返回数据。但是,如果在 updated_at 而不是 assignment_at 上运行相同的查询,则弹性搜索返回 0 结果。 assign_at 和 updated_at 都具有相同的映射和相同的数据,直到下面的查询不返回任何结果。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | { "query": { "nested": { "path":"issue_org_states", "range": { "updated_at": { "from":"2017-10-09T00:00:00.000Z", "to":"2017-10-09T23:59:59.999Z", "include_lower": true, "include_upper": true } } } } } |
如果我在这里遗漏了什么,请帮忙。
在 elasticsearch 5.4.0 上测试并针对 issue_org_states.updated_at 和 issue_org_states.assigned_at 进行查询可以正常工作。您可能想再次查看您的实际命令行。
我的查询如下,基于此文档
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | curl -XGET -u elastic:changeme localhost:9200/issues/issues/_search?pretty -d '{ "query": { "nested": { "path":"issue_org_states", "query" : { "range": { "issue_org_states.updated_at": { "gte":"2017-10-09T00:00:00.000Z", "le":"2017-10-09T23:59:59.999Z" } } } } } }' curl -XGET -u elastic:changeme localhost:9200/issues/issues/_search?pretty -d '{ "query": { "nested": { "path":"issue_org_states", "query" : { "range": { "issue_org_states.assigned_at": { "gte":"2017-10-09T00:00:00.000Z", "le":"2017-10-09T23:59:59.999Z" } } } } } }' |
映射定义,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | curl -XPUT -u elastic:changeme localhost:9200/issues -d '{ "mappings": { "issues": { "properties": { "captured_by": { "type":"long" }, "captured_on": { "type":"date", "format":"dateOptionalTime" }, "description": { "type":"string" }, "id": { "type":"string", "index":"not_analyzed" }, "updated_at": { "type":"date", "format":"dateOptionalTime" }, "issue_org_states": { "type":"nested", "properties": { "assigned_at": { "type":"date", "format":"dateOptionalTime" }, "assigned_by": { "type":"long" }, "updated_at": { "type":"date", "format":"dateOptionalTime" }, "updated_by": { "type":"long" } } } } } } }' |
和你一样的数据。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | curl -XPOST -u elastic:changeme localhost:9200/issues/issues -d '{ "id":"13f3bf09-08cb-4464-b326-15872bdb0870", "description":"Sloppy paint job", "captured_on":"2017-10-09T09:24:01.928Z", "captured_by": 1, "updated_at":"2017-10-09T12:47:22.982Z", "issue_org_states": [ { "updated_at":"2017-10-09T12:47:22.982Z", "updated_by": 1, "assigned_at":"2017-10-09T12:47:22.982Z", "assigned_by": 1879048240 } ] }' |