Created
November 1, 2012 03:27
-
-
Save jch/3989608 to your computer and use it in GitHub Desktop.
experimenting with elasticsearch and email searches
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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": "[email protected]" | |
}' | |
echo | |
echo "Analyze 'jerry'" | |
curl 'localhost:19200/emails/[email protected]&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