Skip to content

Instantly share code, notes, and snippets.

@rashidkpc
Created July 30, 2013 04:39
Show Gist options
  • Save rashidkpc/6110289 to your computer and use it in GitHub Desktop.
Save rashidkpc/6110289 to your computer and use it in GitHub Desktop.
# This command returns a terms facet of size 12
# eg, every term in the terms index. Ordered by count they are:
# term12 (120) term11 (110) term10 (100) term9 (90) term8 (80) term7 (70)
# term6 (60) term5 (50) term4 (40) term3 (30) term2 (20) term1 (10)
curl -XGET 'http://localhost:9200/terms/_search?pretty' -d '{
"facets": {
"terms": {
"terms": {
"field": "term",
"size": 12,
"order": "count",
"exclude": []
},
"facet_filter": {
"fquery": {
"query": {
"filtered": {
"query": {
"bool": {
"should": [
{
"query_string": {
"query": "*"
}
}
]
}
},
"filter": {
"bool": {
"must": [
{
"match_all": {}
},
{
"bool": {
"must": [
{
"match_all": {}
}
]
}
}
]
}
}
}
}
}
}
}
},
"size": 0
}'
# This is the same terms facet, with a size of 5.
# It SHOULD return term12 (120) term11 (110) term10 (100) term9 (90) term8 (80)
# Instead it returns term12 (120) term11 (110) term9 (90) term10 (84) term8 (69)
# Note the complete count of terms 12,11 and 9, and the incomplete cunts of 10 and 8
# and that 9 appears before 10.
curl -XGET 'http://localhost:9200/terms/_search?pretty' -d '{
"facets": {
"terms": {
"terms": {
"field": "term",
"size": 5,
"order": "count",
"exclude": []
},
"facet_filter": {
"fquery": {
"query": {
"filtered": {
"query": {
"bool": {
"should": [
{
"query_string": {
"query": "*"
}
}
]
}
},
"filter": {
"bool": {
"must": [
{
"match_all": {}
},
{
"bool": {
"must": [
{
"match_all": {}
}
]
}
}
]
}
}
}
}
}
}
}
},
"size": 0
}'
#!/usr/bin/ruby
# this script generates 12 terms, each with i*10 occurences
# eg, term12 appears 120 times, term8 appears 80 times
# It stores them in an index called 'terms'
require 'rubygems'
require 'tire'
index = "terms"
result = []
i = 0
12.times do
i += 1
k = i*10;
k.times do
event = {
:term => "term#{i}",
:type => 'term',
}
result.push(event)
end
end
puts result
Tire.index index do
import result
end
@loveybot
Copy link

Yay Ruby!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment