Skip to content

Instantly share code, notes, and snippets.

@albsen
Created March 9, 2012 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save albsen/2006165 to your computer and use it in GitHub Desktop.
Save albsen/2006165 to your computer and use it in GitHub Desktop.
custom analyzer question
curl -XDELETE 'http://localhost:9200/twitter/'
curl -XPUT 'http://localhost:9200/twitter/' -d '{
"settings" : {
"analysis":
{
"filter": {
"synonym_filter" : {
"type" : "synonym",
"synonyms": [
"i-phone 4, i phone 4, iphone 4 => iphone4"
],
"ignore_case": "true"
},
"front_edgengram_filter": {
"type": "edgeNGram","max_gram": 15, "side": "front",
"min_gram": 3
}
},
"analyzer": {
"k_search": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"synonym_filter"
]
},
"k_index": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"synonym_filter",
"front_edgengram_filter"
]
}
}
}
}
}'
echo '\n mapping'
curl -XPUT 'http://localhost:9200/twitter/tweet/_mapping?pretty' -d '
{
"tweet" : {
"dynamic": true,
"properties" : {
"message" : {
"type" : "string", "store" : "yes",
"index_analyzer": "k_index",
"search_analyzer": "k_search"
}
}
}
}
'
echo '\n done mapping'
# curl -XPUT 'http://localhost:9200/twitter/tweet/1?pretty' -d '{
# "message" : "iphone 4 black 32GB factory unlocked, brand new, two days used, axiom warranty"
# }'
curl -XPUT 'http://localhost:9200/twitter/tweet/1?pretty' -d '{
"message" : "iphone 4"
}'
sleep 10
# curl -XGET 'http://localhost:9200/classifieds/classified_mb/_mapping?pretty=true'
echo '\n done putting'
curl -XGET 'localhost:9200/twitter/_analyze?analyzer=k_index&pretty' -d 'iphone 4'
echo '\n done index analyzing sample'
curl -XGET 'localhost:9200/twitter/_analyze?analyzer=k_search&pretty' -d 'iphone 4'
echo '\n done search analyzing sample'
echo '\n\n search via term (not analyzed)'
curl -XGET 'http://localhost:9200/twitter/tweet/_search?pretty' -d '{
"query" : {
"term" : { "message" : "iphone 4" }
}
}
'
echo '\n\n searching with query_string'
curl -XGET 'http://localhost:9200/twitter/tweet/_search?pretty' -d '{
"explain": true,
"query" : {
"query_string" : {
"fields": ["message"],
"default_operator": "AND",
"query" : "iphone 4"
}
}
}
'
echo '\n\n searching with text'
curl -XGET 'http://localhost:9200/twitter/tweet/_search?pretty' -d '{
"query" : {
"text" : {
"message" : "iphone 4"
}
}
}
'
echo '\n done searching'
echo '\n should get:'
curl -XGET 'http://localhost:9200/twitter/tweet/1?pretty'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment