Hi everyone, I am trying to search a keyword in date range. Can anyone help me out?
curl -XGET 'http://localhost:9200/201706/_search ' -d '{ "query" :{ "bool" : { "must" : [{ "match" : { "message": "isis"} }, { "range" :{ "created_at" :{ "gte" :"2017-06-01", "lte" : "2017-06-30", "format" :"yyyy/mm/dd||yyyy"}}}]}}}'
Thanks, Akhil
             
            
               
               
               
            
            
           
          
            
            
              It looks like your date pattern does not match the data: 2017-06-01 vs yyyy/mm/dd. Based on the example in the documentation  it also looks like your pattern should be yyyy-MM-dd.
             
            
               
               
              1 Like 
            
            
           
          
            
            
              I changed date pattern Christian, still no help.
             
            
               
               
               
            
            
           
          
            
            
              What does your query look like now?
             
            
               
               
               
            
            
           
          
            
            
              curl -XGET 'http://localhost:9200/201706/_search ' -d '{ "query" :{ "bool" : { "must" : [{ "match" : { "message": "isis"} }, { "range" :{ "created_at" :{ "gte" :"2017/06/01", "lte" : "2017/06/30", "format" :"yyyy/mm/dd||yyyy"}}}]}}}'
             
            
               
               
               
            
            
           
          
            
            
              According to the example it should be MM instead of mm.
             
            
               
               
               
            
            
           
          
            
            
              I am getting 0 hits 
{"took":11,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}
             
            
               
               
               
            
            
           
          
            
            
              Tried this query 
curl -XGET 'http://localhost:9200/201706/_search ' -d '{ "query" :{ "bool" : { "must" : [{ "match" : { "message": "isis"} }, { "range" :{ "created_at" :{ "gte" :"2017/06/01", "lte" : "2017/06/30", "format" :"yyyy/MM/dd||yyyy"}}}]}}}'
and got this result 
{"took":11,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}
             
            
               
               
               
            
            
           
          
            
            
              What happens if you remove one of the 2 clauses, e.g. query just with filter or just with range query?
             
            
               
               
               
            
            
           
          
            
            
              Then it works fine, but I want is to search a particular keyword in a particular date range.
             
            
               
               
               
            
            
           
          
            
            
              When you search using just the filter, how many documents fit within the time range? Can you show a document that the full query should find?
             
            
               
               
               
            
            
           
          
            
            
              Damn! Now even my range query is not working 
curl -XGET 'localhost:9200/_search?pretty'  -d' 
{ 
"query": { 
"range" : { 
"created_at" : { 
"gte": "2017-06-01", 
"lte": "2017-06-30", 
"format": "yyyy-MM/dd||yyyy" 
} 
} 
} 
} 
'
             
            
               
               
               
            
            
           
          
            
            
              Index mapping 
curl -XPOST 'http://localhost:9200/201706/facebook ' -d '{ "mappings" : { "facebook" : { "properties" : { 
"feed_id" : { "type" : "string"}, 
"id" : { "type" : "string"}, 
"type" : { "type" : "string"}, 
"message" : { "type" : "string"}, 
"created_at" : { "type" : "date"}, 
"updated_time" : { "type" : "date"}, 
"sentiment_score" : { "type" : "string"}, 
"sentiment_category" : { "type" : "string"}, 
"total_shares" : { "type" : "string"}, 
"total_likes" : { "type" : "string"}, 
"total_comments" : { "type" : "string"}, 
"source" : { "type" : "string"}, 
"picture" : { "type" : "string"}, 
"media_type" : { "type" : "string"}, 
"duration" : { "type" : "string"}, 
"name" : { "type" : "string"}, 
"fb_user_id" : { "type" : "string"} 
} 
} 
} 
}'
             
            
               
               
               
            
            
           
          
            
            
              Can you show me a sample doc available in the index
             
            
               
               
               
            
            
           
          
            
            
              I tried this and it works:
curl -XPUT 127.0.0.1:9200/rangetest/test/1 -d '{"message" : "aaa bbb ccc", "created_at" : "2017-06-15T14:00:00"}'
sleep 1
curl -XGET 'http://localhost:9200/test/test/_search' -d '{ "query" :{ "bool" : { "must" : [{ "match" : { "message": "bbb"} }, { "range" :{ "created_at" :{ "gte" :"2017/06/01", "lte" : "2017/06/30", "format" :"yyyy/MM/dd"}}}]}}}'
 
             
            
               
               
              1 Like 
            
            
           
          
            
            
              Can you show your index mapping once???
             
            
               
               
               
            
            
           
          
            
              
                system  
                (system)
                  Closed 
               
              
                  
                    August 21, 2017,  8:18am
                   
                   
              19 
               
             
            
              This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.