Created
April 2, 2012 22:32
-
-
Save dantam/2287663 to your computer and use it in GitHub Desktop.
ElasticSearch difficulties with edge ngram and synonym analyzer
This file contains 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
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