Created
July 28, 2012 06:00
-
-
Save anonymous/3192015 to your computer and use it in GitHub Desktop.
Date filter (numeric_range) on nested item
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -XPUT http://localhost:9200/myindex | |
curl -XPUT http://localhost:9200/myindex/clinic/_mapping -d '{ | |
"clinic": { | |
"properties": { | |
"hours": { | |
"type": "nested", | |
"properties": { | |
"close": { | |
"type": "date", | |
"format": "HH:mm" | |
}, | |
"day": { | |
"type": "long" | |
}, | |
"open": { | |
"type": "date", | |
"format": "HH:mm" | |
} | |
} | |
}, | |
"name": { | |
"type": "string" | |
} | |
} | |
} | |
} | |
' | |
curl -XPUT http://localhost:9200/myindex/clinic/1 -d ' | |
{ "name": "Clinic 1", | |
"hours": [ {"day": 0, "open": "09:00", "close": "18:00"}, | |
{"day": 1, "open": "09:00", "close": "18:00"} ] | |
} | |
' | |
curl -XPUT http://localhost:9200/myindex/clinic/2 -d ' | |
{ "name": "Clinic 2", | |
"hours": [ {"day": 0, "open": "07:00", "close": "16:00"}, | |
{"day": 1, "open": "08:00", "close": "17:00"} ] | |
} | |
' | |
curl -XGET http://localhost:9200/myindex/clinic/_search?pretty=true-d ' | |
{ | |
"query": { | |
"nested" : { | |
"path" : "hours", | |
"score_mode" : "avg", | |
"filter" : { | |
"bool" : { | |
"must" : [ | |
{ | |
"numeric_range" : {"hours.open" : { | |
"lte": "08:00"} | |
} | |
} | |
] | |
} | |
} | |
} | |
} | |
} | |
' | |
{ | |
"took" : 4, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 5, | |
"successful" : 5, | |
"failed" : 0 | |
}, | |
"hits" : { | |
"total" : 2, | |
"max_score" : 1.0, | |
"hits" : [ { | |
"_index" : "myindex", | |
"_type" : "clinic", | |
"_id" : "1", | |
"_score" : 1.0, "_source" : | |
{ "name": "Clinic 1", | |
"hours": [ {"day": 0, "open": "09:00", "close": "18:00"}, | |
{"day": 1, "open": "09:00", "close": "18:00"} ] | |
} | |
}, { | |
"_index" : "myindex", | |
"_type" : "clinic", | |
"_id" : "2", | |
"_score" : 1.0, "_source" : | |
{ "name": "Clinic 2", | |
"hours": [ {"day": 0, "open": "07:00", "close": "16:00"}, | |
{"day": 1, "open": "08:00", "close": "17:00"} ] | |
} | |
} ] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment