ElasticSearch日期范围查询返回不正确的结果

时间:2016-03-03 17:41:54

标签: elasticsearch

使用以下日期范围查询包括我们希望过滤的日期范围之外的结果。

{
   "query" : {

         "range" : {
           "account.expiry" : {
             "gte" : "2016-03-03T00:00:00.000Z",
             "lt" : "2017-03-02T00:00:00.000Z"
           }
         }
   },
   "_source" : {
     "includes" : [ "account.expiry"],
     "excludes" : [ ]
   }

 }

我尝试了各种不同的变体(使用'来自'来自'而不是''' lte')。 / p>

我检查了索引的映射,它们对我来说看起来不错(Elastic没有将字段视为字符串)。这是相关部分:

{
    "myindex.dev": {
        "aliases": {},
        "mappings": {
            "account": {
                "properties": {
                    "account": {
                        "properties": {
                            "expiry": {
                                "type": "date",
                                "format": "dateOptionalTime"
                            }
                        }
                    }
                }
            }
        }

    }
}

我已经编写了一个单元测试,它在本地旋转ES并用数据填充它,这似乎没有同样的问题。我已经检查过,他们都使用相同版本的ElasticSearch。从不同的JRE运行测试似乎没有什么区别。

我感谢您提供任何帮助!

编辑:

这些是我从此查询中获得的结果。我正在制作重现的步骤,但在我自己的机器上运行时似乎表现得很好

(
    {
    "took": 9,
    "timed_out": false,
    "_shards": {
        "total": 3,
        "successful": 3,
        "failed": 0
    },
    "hits": {
        "total": 13234,
        "max_score": 1,
        "hits": [
            {
                "_index": "accounts.dev",
                "_type": "account",
                "_id": "4328398",
                "_score": 1,
                "_source": {
                    "account": {
                        "expiry": "2012-09-30T00:00:00Z"
                    }
                }
            },
            {
                "_index": "accounts.dev",
                "_type": "account",
                "_id": "7504549",
                "_score": 1,
                "_source": {
                    "account": {
                        "expiry": "2012-09-30T00:00:00Z"
                    }
                }
            },
            {
                "_index": "accounts.dev",
                "_type": "account",
                "_id": "8333546",
                "_score": 1,
                "_source": {
                    "account": {
                        "expiry": "2012-09-30T00:00:00Z"
                    }
                }
            },
            {
                "_index": "accounts.dev",
                "_type": "account",
                "_id": "12693814",
                "_score": 1,
                "_source": {
                    "account": {
                        "expiry": "2012-09-30T00:00:00Z"
                    }
                }
            },
            {
                "_index": "accounts.dev",
                "_type": "account",
                "_id": "32583326",
                "_score": 1,
                "_source": {
                    "account": {
                        "expiry": "2012-09-30T00:00:00Z"
                    }
                }
            },
            {
                "_index": "accounts.dev",
                "_type": "account",
                "_id": "66828717",
                "_score": 1,
                "_source": {
                    "account": {
                        "expiry": "2013-09-07T00:00:00Z"
                    }
                }
            },
            {
                "_index": "accounts.dev",
                "_type": "account",
                "_id": "66905991",
                "_score": 1,
                "_source": {
                    "account": {
                        "expiry": "2013-11-25T00:00:00Z"
                    }
                }
            },
            {
                "_index": "accounts.dev",
                "_type": "account",
                "_id": "12843517",
                "_score": 1,
                "_source": {
                    "account": {
                        "expiry": "2016-02-23T00:00:00Z"
                    }
                }
            },
            {
                "_index": "accounts.dev",
                "_type": "account",
                "_id": "43597281",
                "_score": 1,
                "_source": {
                    "account": {
                        "expiry": "2013-06-12T00:00:00Z"
                    }
                }
            },
            {
                "_index": "accounts.dev",
                "_type": "account",
                "_id": "43597291",
                "_score": 1,
                "_source": {
                    "account": {
                        "expiry": "2012-12-31T00:00:00Z"
                    }
                }
            }
        ]
    }
}

编辑2:

在回复评论时,是的,实际上源文档中也有一个嵌套的到期字段......它看起来像这样。

 "account": {
    "permissionSets": [
        {
            "expiry": "2013-10-29T00:00:00Z"
        },
        {
            "expiry": "2016-09-30T00:00:00Z"
        },
        {
            "expiry": "2012-09-30T00:00:00Z"
        },
        {
            "expiry": "2012-09-30T00:00:00Z"
        }
    ],
    "expiry": "2012-09-30T00:00:00Z"

0 个答案:

没有答案