Help required


(Akhil Prashar) #1

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


(Christian Dahlqvist) #2

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.


(Akhil Prashar) #3

I changed date pattern Christian, still no help.


(Christian Dahlqvist) #4

What does your query look like now?


(Akhil Prashar) #5

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"}}}]}}}'


(Christian Dahlqvist) #6

According to the example it should be MM instead of mm.


(Akhil Prashar) #7

I am getting 0 hits
{"took":11,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}


(Akhil Prashar) #8

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":[]}}


(Christian Dahlqvist) #9

What happens if you remove one of the 2 clauses, e.g. query just with filter or just with range query?


(Akhil Prashar) #10

Then it works fine, but I want is to search a particular keyword in a particular date range.


(Christian Dahlqvist) #11

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?


(Akhil Prashar) #12

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"
}
}
}
}
'


(Ravi Shanker Reddy) #13

yyyy-MM-dd Try with this


(Akhil Prashar) #14

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"}
}
}
}
}'


(Ravi Shanker Reddy) #15

Can you show me a sample doc available in the index


(Christian Dahlqvist) #16

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"}}}]}}}'

(Ravi Shanker Reddy) #17

Can you show your index mapping once???


(Akhil Prashar) #18

Sorry for the delay Ravi


(system) #19

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.