Skip to content

Instantly share code, notes, and snippets.

@dadoonet
Created April 5, 2013 17:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dadoonet/5320947 to your computer and use it in GitHub Desktop.
Save dadoonet/5320947 to your computer and use it in GitHub Desktop.
Extract domain name and compute size with terms stat facet
# Delete Test index
curl -XDELETE 'http://localhost:9200/facets_test/'
# Create index and analyzer
curl -XPUT 'http://localhost:9200/facets_test?pretty' -d '{
"settings":{
"analysis": {
"analyzer": {
"email":{
"type": "custom",
"tokenizer":"uax_url_email",
"filter":["domain"]
}
},
"filter": {
"domain":{
"type": "pattern_replace",
"pattern":".+@([^.]+\\..+)",
"replacement":"$1"
}
}
}
}
}'
# Testing analyzer
curl 'localhost:9200/facets_test/_analyze?pretty=1&analyzer=email' -d 'abc@my.domain.com'
# my.domain.com
# Put mapping
curl -XPUT "http://localhost:9200/facets_test/logs/_mapping" -d '{
"logs" : {
"properties" : {
"email_id" : {
"type" : "string", "analyzer" : "email"
},
"size" : {
"type" : "long"
},
"title" : {
"type" : "string"
}
}
}
}'
# Index documents
curl -XPOST "http://localhost:9200/facets_test/logs" -d '{"title" : "First Line", "email_id": "abc@domain.com", "size": 1024}'
curl -XPOST "http://localhost:9200/facets_test/logs" -d '{"title" : "Second Line", "email_id": "def@domain.com", "size": 2048}'
curl -XPOST "http://localhost:9200/facets_test/logs" -d '{"title" : "Third Line", "email_id": "ghi@domain.com", "size": 3096}'
curl -XPOST "http://localhost:9200/facets_test/logs" -d '{"title" : "Fourth Line", "email_id": "abc@domainname.com", "size": 1024}'
curl -XPOST "http://localhost:9200/facets_test/logs" -d '{"title" : "Fifth Line", "email_id": "def@domainname.com", "size": 2048}'
curl -XPOST "http://localhost:9200/facets_test/logs" -d '{"title" : "Fifth Line", "email_id": "def@domainname.com", "size": 3096}'
# Refresh index
curl -XPOST 'http://localhost:9200/facets_test/_refresh'
# Compute facet
curl -XPOST 'http://localhost:9200/facets_test/_search?pretty' -d '{
"query" : {
"match_all" : { }
},
"facets" : {
"tag_price_stats" : {
"terms_stats" : {
"key_field" : "email_id",
"value_field" : "size"
}
}
}
}'
@brian-from-fl
Copy link

Cool! Thanks!

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