为什么弹性搜索范围查询中的双引号会给出不同的结果?

时间:2016-12-13 12:55:21

标签: elasticsearch

如果我用秒(长)来引用纪元时间,则范围查询似乎返回正确的结果,因为直接输入数字会产生错误的结果。那是为什么?

非常感谢!

使用ES 1.7

架构:

"test": {
    "mappings": {
        "type1": {
            "dynamic_templates": [{
                "template1": {
                    "mapping": {
                        "format": "date_time",
                        "type": "date",
                        "index": "not_analyzed",
                        "store": "yes",
                        "numeric_resolution": "seconds"
                    },
                    "match": "*_date"
                }
            }],
            "properties": {
                "end_date": {
                    "type": "date",
                    "store": true,
                    "format": "date_time",
                    "numeric_resolution": "seconds"
                },
                "start_date": {
                    "type": "date",
                    "store": true,
                    "format": "date_time",
                    "numeric_resolution": "seconds"
                }
            }
        }
    }
}

数据:

{
    "took": 1,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
    },
    "hits": {
        "total": 3,
        "max_score": 1,
        "hits": [{
            "_index": "aaaa",
            "_type": "type1",
            "_id": "AVj3-lk5IN_78Kc5kFZP",
            "_score": 1,
            "_source": {
                "start_date": 1480600726,
                "end_date": 1483192726
            }
        }, {
            "_index": "aaaa",
            "_type": "type1",
            "_id": "AVj38YLoIN_78Kc5kFZH",
            "_score": 1,
            "_source": {
                "start_date": 1481628525,
                "end_date": 1481628544
            }
        }]
    }
}

查询:

{
  "query": {
    "range": {
      "start_date": {
        "gte": "1481628525"
      }
    }
  }
}

结果:

{
    "took": 1,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
    },
    "hits": {
        "total": 1,
        "max_score": 1,
        "hits": [{
            "_index": "aaaa",
            "_type": "type1",
            "_id": "AVj38YLoIN_78Kc5kFZH",
            "_score": 1,
            "_source": {
                "start_date": 1481628525,
                "end_date": 1481628544
            }
        }]
    }
}

不带引号的查询:

{
  "query": {
    "range": {
      "start_date": {
        "gte": 1481628525
      }
    }
  }
}

结果:

{
    "took": 1,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
    },
    "hits": {
        "total": 2,
        "max_score": 1,
        "hits": [{
            "_index": "aaaa",
            "_type": "type1",
            "_id": "AVj3-lk5IN_78Kc5kFZP",
            "_score": 1,
            "_source": {
                "start_date": 1480600726,
                "end_date": 1483192726
            }
        }, {
            "_index": "aaaa",
            "_type": "type1",
            "_id": "AVj38YLoIN_78Kc5kFZH",
            "_score": 1,
            "_source": {
                "start_date": 1481628525,
                "end_date": 1481628544
            }
        }]
    }
}

0 个答案:

没有答案