Skip to content

Instantly share code, notes, and snippets.

@dadoonet
Created July 25, 2012 19:00
Show Gist options
  • Save dadoonet/3177911 to your computer and use it in GitHub Desktop.
Save dadoonet/3177911 to your computer and use it in GitHub Desktop.
Count Query with not_analyzed mapping
curl -XDELETE 'http://localhost:9200/myindex'
curl -XPUT 'http://localhost:9200/myindex'
curl -XPUT 'http://localhost:9200/myindex/myindext/_mapping' -d '{
"myindext": {
"properties": {
"user": {
"type": "string"
},
"message": {
"type": "string"
},
"post_date": {
"type": "date"
},
"UserGender": {
"type": "string",
"index": "not_analyzed"
}
}
}
}'
curl -XPUT 'http://localhost:9200/myindex/myindext/1' -d '{
"_id" : 1,
"user" : "sachin",
"post_date" : "2012-1-02T00:00:00",
"message" : "lovely world 0",
"UserGender":"M"
}'
curl -XPUT 'http://localhost:9200/myindex/myindext/2' -d '{
"_id" : 2,
"user" : "sachin",
"post_date" : "2012-1-03T00:00:00",
"message" : "lovely world 1",
"UserGender":"M"
}'
curl -XPUT 'http://localhost:9200/myindex/myindext/3' -d '{
"_id" : 3,
"user" : "ni",
"post_date" : "2012-1-10T00:00:00",
"message" : "lovely world 2",
"UserGender":"F"
}'
curl -XPUT 'http://localhost:9200/myindex/myindext/4' -d '{
"_id" : 4,
"user" : "sumit",
"post_date" : "2012-1-04T00:00:00",
"message" : "lovely world 3",
"UserGender":"M"
}'
curl -XGET 'http://localhost:9200/myindex/myindext/_count' -d '{
"filtered": {
"query": {
"range": {
"post_date": {
"from": "2012-1-02T00:00:00",
"to": "2012-1-03T00:00:00"
}
}
},
"filter": {
"term": {
"UserGender": "M"
}
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment