Skip to content

Instantly share code, notes, and snippets.

@jch
Created November 1, 2012 03:27
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jch/3989608 to your computer and use it in GitHub Desktop.
Save jch/3989608 to your computer and use it in GitHub Desktop.
experimenting with elasticsearch and email searches
#!/bin/sh
# Start fresh
curl -q -XDELETE 'localhost:19200/emails?pretty' 2>1 1>/dev/null
# Create index 'emails' with a mapping for type 'user', and settings for
# custom email analyzers
echo "Create Index"
curl -XPUT 'localhost:19200/emails?pretty' -d '{
"settings": {
"analysis":{
"analyzer":{
"email_analyzer":{
"type":"stop",
"stopwords":[ "com" ]
}
}
}
},
"mappings": {
"user": {
"properties": {
"email": {
"type": "multi_field",
"fields": {
"email": {"type": "string", "analyzer": "email_analyzer", "boost": 100},
"exact": {"type": "string", "analyzer": "keyword"}
}
}
}
}
}
}'
echo
echo "Index an email"
curl -XPOST 'localhost:19200/emails/user/1?pretty' -d '{
"email": "jerry@github.com"
}'
echo
echo "Analyze 'jerry'"
curl 'localhost:19200/emails/_analyze?text=jerry@github.com&field=user:email&pretty'
echo
echo "Explain email"
curl -XGET 'localhost:19200/emails/user/1/_explain' -d '{
"query": {
"query_string": "github.com"
}
}'
echo
# echo "Search 'jerry'"
# curl 'localhost:19200/emails/_search?q=email:jerry&pretty'
# echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment