Skip to content

Instantly share code, notes, and snippets.

@dantam
Created April 2, 2012 22:32
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 dantam/2287663 to your computer and use it in GitHub Desktop.
Save dantam/2287663 to your computer and use it in GitHub Desktop.
ElasticSearch difficulties with edge ngram and synonym analyzer
set -x
curl -XDELETE 'http://localhost:9200/twitter'
curl -XPUT 'http://localhost:9200/twitter' -d '{
"index" : {
"analysis" : {
"analyzer" : {
"test_analyzer" : {
"type" : "custom",
"tokenizer" : "standard",
"filter" : ["standard", "lowercase", "ngrams", "synonym"]
}
},
"filter" : {
"synonym": {
"type" : "synonym",
"synonyms" : ["try => test"]
},
"ngrams" : {
"side" : "front",
"max_gram" : 255,
"min_gram" : 1, "type" : "edgeNGram"
}
}
}
}
}'
curl -XPUT 'http://localhost:9200/twitter/tweet/_mapping' -d '{
"tweet" : {
"properties" : {
"message" : {
"type" : "string",
"index" : "analyzed",
"index_analyzer" : "test_analyzer",
"search_analyzer" : "default"
}
}
}
}'
curl -XPUT 'http://localhost:9200/twitter/tweet/1' -d '{
"user" : "kimchy",
"post_date" : "2009-11-15T14:12:12",
"message" : "try Elastic Search"
}'
sleep 1
echo "'try' is a 3-gram that is also mapped to a synonym 'test'"
curl -XGET 'http://localhost:9200/twitter/tweet/_search' -d ' {
"query": {
"text": {
"message": {
"query":"try"
}
}
}
}'
curl -XGET 'http://localhost:9200/twitter/tweet/_search' -d ' {
"query": {
"text": {
"message": {
"query":"tr"
}
}
}
}'
curl -XGET 'http://localhost:9200/twitter/tweet/_search' -d ' {
"query": {
"text": {
"message": {
"query":"test"
}
}
}
}'
curl -XGET 'localhost:9200/twitter/_analyze?analyzer=test_analyzer' -d 'try'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment