简体   繁体   中英

Elasticsearch php client date range not working

I'm using the official PHP client from here - https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html

Everything works fine but one thing - filter by date range; The field type in mapping is Date, but I do not getting filtered result. Query structure looks like this and it works fine when I'm executing in Sense chrome plugin:

{
"query": {
    "filtered": {
        "query": {
            "match_all": {}
        },
        "filter": {
            "range": {
                "myfield": {
                    "gt": "2015-01-10"
                }
            }
        }
    }
}

}

mapping for field:

"myfield": {
              "type": "date",
              "format": "dateOptionalTime"
           }

In php client I've tried to check range filter with another field which is not datetype and it works fine, the only problem with datetype fields.

Thanks.

Same problem for me. According the documentation, it should work, but not for me. You didn't post your mapping file, but code below works for me.

Use from instead of gt.

Example:

{
   "query": {
      "filtered": {
         "query": {
            "match_all": {}
         },
         "filter": {
            "range": {
               "myfield": {
                  "from": "2015-01-10"
               }
            }
         }
      }
   }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM