Skip to content

Instantly share code, notes, and snippets.

@dadoonet
Created June 27, 2012 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dadoonet/3007168 to your computer and use it in GitHub Desktop.
Save dadoonet/3007168 to your computer and use it in GitHub Desktop.
Using Terms Stats Facet on "edgeNGram" key field
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 3,
"failed" : 2,
"failures" : [ {
"index" : "dpitestcase",
"shard" : 3,
"status" : 500,
"reason" : "No active shards"
}, {
"index" : "dpitestcase",
"shard" : 4,
"status" : 500,
"reason" : "No active shards"
} ]
},
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [ ]
},
"facets" : {
"path_lat" : {
"_type" : "terms_stats",
"missing" : 0,
"terms" : [ {
"term" : "1022232003013110123223112",
"count" : 1,
"total_count" : 1,
"min" : 46.20715933,
"max" : 46.20715933,
"total" : 46.20715933,
"mean" : 46.20715933
}, {
"term" : "102223200301311012322311",
"count" : 1,
"total_count" : 1,
"min" : 46.20715933,
"max" : 46.20715933,
"total" : 46.20715933,
"mean" : 46.20715933
}, {
"term" : "10222320030131101232231",
"count" : 1,
"total_count" : 1,
"min" : 46.20715933,
"max" : 46.20715933,
"total" : 46.20715933,
"mean" : 46.20715933
}, {
"term" : "1022232003013110123223",
"count" : 1,
"total_count" : 1,
"min" : 46.20715933,
"max" : 46.20715933,
"total" : 46.20715933,
"mean" : 46.20715933
}, {
"term" : "102223200301311012322",
"count" : 1,
"total_count" : 1,
"min" : 46.20715933,
"max" : 46.20715933,
"total" : 46.20715933,
"mean" : 46.20715933
}, {
"term" : "10222320030131101232",
"count" : 1,
"total_count" : 1,
"min" : 46.20715933,
"max" : 46.20715933,
"total" : 46.20715933,
"mean" : 46.20715933
}, {
"term" : "1022232003013110123",
"count" : 1,
"total_count" : 1,
"min" : 46.20715933,
"max" : 46.20715933,
"total" : 46.20715933,
"mean" : 46.20715933
}, {
"term" : "102223200301311012",
"count" : 1,
"total_count" : 1,
"min" : 46.20715933,
"max" : 46.20715933,
"total" : 46.20715933,
"mean" : 46.20715933
}, {
"term" : "10222320030131101",
"count" : 1,
"total_count" : 1,
"min" : 46.20715933,
"max" : 46.20715933,
"total" : 46.20715933,
"mean" : 46.20715933
}, {
"term" : "1022232003013110",
"count" : 1,
"total_count" : 1,
"min" : 46.20715933,
"max" : 46.20715933,
"total" : 46.20715933,
"mean" : 46.20715933
}, {
"term" : "102223200301311",
"count" : 1,
"total_count" : 1,
"min" : 46.20715933,
"max" : 46.20715933,
"total" : 46.20715933,
"mean" : 46.20715933
}, {
"term" : "10222320030131",
"count" : 1,
"total_count" : 1,
"min" : 46.20715933,
"max" : 46.20715933,
"total" : 46.20715933,
"mean" : 46.20715933
}, {
"term" : "1022232003013",
"count" : 1,
"total_count" : 1,
"min" : 46.20715933,
"max" : 46.20715933,
"total" : 46.20715933,
"mean" : 46.20715933
}, {
"term" : "102223200301",
"count" : 1,
"total_count" : 1,
"min" : 46.20715933,
"max" : 46.20715933,
"total" : 46.20715933,
"mean" : 46.20715933
}, {
"term" : "10222320030",
"count" : 1,
"total_count" : 1,
"min" : 46.20715933,
"max" : 46.20715933,
"total" : 46.20715933,
"mean" : 46.20715933
}, {
"term" : "1022232003",
"count" : 1,
"total_count" : 1,
"min" : 46.20715933,
"max" : 46.20715933,
"total" : 46.20715933,
"mean" : 46.20715933
}, {
"term" : "102223200",
"count" : 1,
"total_count" : 1,
"min" : 46.20715933,
"max" : 46.20715933,
"total" : 46.20715933,
"mean" : 46.20715933
}, {
"term" : "10222320",
"count" : 1,
"total_count" : 1,
"min" : 46.20715933,
"max" : 46.20715933,
"total" : 46.20715933,
"mean" : 46.20715933
}, {
"term" : "1022232",
"count" : 1,
"total_count" : 1,
"min" : 46.20715933,
"max" : 46.20715933,
"total" : 46.20715933,
"mean" : 46.20715933
}, {
"term" : "102223",
"count" : 1,
"total_count" : 1,
"min" : 46.20715933,
"max" : 46.20715933,
"total" : 46.20715933,
"mean" : 46.20715933
}, {
"term" : "10222",
"count" : 1,
"total_count" : 1,
"min" : 46.20715933,
"max" : 46.20715933,
"total" : 46.20715933,
"mean" : 46.20715933
}, {
"term" : "1022",
"count" : 1,
"total_count" : 1,
"min" : 46.20715933,
"max" : 46.20715933,
"total" : 46.20715933,
"mean" : 46.20715933
}, {
"term" : "102",
"count" : 1,
"total_count" : 1,
"min" : 46.20715933,
"max" : 46.20715933,
"total" : 46.20715933,
"mean" : 46.20715933
}, {
"term" : "10",
"count" : 1,
"total_count" : 1,
"min" : 46.20715933,
"max" : 46.20715933,
"total" : 46.20715933,
"mean" : 46.20715933
}, {
"term" : "1",
"count" : 1,
"total_count" : 1,
"min" : 46.20715933,
"max" : 46.20715933,
"total" : 46.20715933,
"mean" : 46.20715933
} ]
}
}
}
# First delete old index
curl -XDELETE localhost:9200/dpitestcase
# Then creat the index with settings
curl -XPUT localhost:9200/dpitestcase -d '
{
"settings":{
"analysis":{
"analyzer":{
"myanalyzer":{
"type":"custom",
"tokenizer":"mytokenizer"
}
},
"tokenizer":{
"mytokenizer":{
"type":"edgeNGram",
"min_gram":"1",
"max_gram":"25",
"side":"front"
}
}
}
},
"mappings":{
"point":{
"properties":{
"created_at":{
"type":"date"
},
"id":{
"type":"string"
},
"lat":{
"type":"double"
},
"lng":{
"type":"double"
},
"location":{
"type":"geo_point"
},
"path":{
"type":"string",
"analyzer":"myanalyzer"
}
}
}
}
}
'
# Push a document
curl -XPUT localhost:9200/dpitestcase/point/1 -d '
{
"id":"1",
"location":{
"lat":46.20715933,
"lon":6.14494212
},
"lat":46.20715933,
"lng":6.14494212,
"path":"1022232003013110123223112",
"created_at":1339491413
}
'
# Refresh the index befor we can search
curl -XPOST 'http://localhost:9200/dpitestcase/_refresh'
# And now we search
curl -X GET "http://localhost:9200/dpitestcase/point/_search?pretty=true" -d '
{
"query":{
"query_string":{
"query":"*"
}
},
"facets":{
"path_lat":{
"terms_stats":{
"key_field":"path",
"value_field":"lat",
"size":0
},
"facet_filter":{
"geo_bounding_box":{
"location":{
"top_left":{
"lat":84.4740645845916,
"lon":-179.999999
},
"bottom_right":{
"lat":-75.67219739055291,
"lon":179.999999
}
}
}
}
}
},
"size":0
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment