Range filter does not work

I use elasticsearch search engine, and when I run the code below, the returned results do not meet the criteria of the range (I get items with a published date below the desired limit):

#!/bin/bash curl -X GET 'http://localhost:9200/newsidx/news/_search?pretty' -d '{ "fields": [ "art_text", "title", "published", "category" ], "query": { "bool": { "should": [ { "fuzzy": {"art_text": {"boost": 89, "value": "google" }} }, { "fuzzy": {"art_text": {"boost": 75, "value": "twitter" }} } ], "minimum_number_should_match": 1 } }, "filter" : { "range" : { "published" : { "from" : "2013-04-12 00:00:00" } } } } ' 

I also tried to make the range clause mandatory, inside the bool query, but the results were the same.

Edit: I use elasticsearch to search in mongodb across the river fin. This is the script I ran to look for mongodb db with ES:

 #!/bin/bash curl -X PUT localhost:9200/_river/mongodb/_meta -d '{ "type":"mongodb", "mongodb": { "db": "newsful", "collection": "news" }, "index": { "name": "newsidx", "type": "news" } }' 

In addition, I did not create other indexes.

Edit 2:

Es display view:

 http://localhost:9200/newsidx/news/_mapping published: { type: "string" } 
+4
source share
1 answer

The reason is your mapping. The published field that you use as the date is indexed as a string. Probably because the date format you are using is not used by default in elasticsearch, so the field type is not auto-detected and it is indexed as a simple string.

You must change your mapping using put mapping api . You need to define the published field as the date there, indicating the format you are using (there may be more than one), and reindex your data.

After that, your range filter should work!

+2
source

All Articles