Skip to content

Instantly share code, notes, and snippets.

@polyfractal
Created January 15, 2013 21:56
Show Gist options
  • Save polyfractal/4542494 to your computer and use it in GitHub Desktop.
Save polyfractal/4542494 to your computer and use it in GitHub Desktop.
#create a test index with shingle mapping
curl -XPUT localhost:9200/test -d '{
"settings":{
"index":{
"analysis":{
"analyzer":{
"analyzer_shingle":{
"tokenizer":"standard",
"filter":["standard", "lowercase", "filter_stop", "filter_shingle"]
}
},
"filter":{
"filter_shingle":{
"type":"shingle",
"max_shingle_size":5,
"min_shingle_size":2,
"output_unigrams":"true"
},
"filter_stop":{
"type":"stop",
"enable_position_increments":"false"
}
}
}
}
},
"mappings":{
"product":{
"properties":{
"title":{
"search_analyzer":"analyzer_shingle",
"index_analyzer":"analyzer_shingle",
"type":"string"
}
}
}
}
}'
#Add some docs to the index
curl -XPOST localhost:9200/test/product/1 -d '{"title" : "Sample product title for shingles"}'
curl -XPOST localhost:9200/test/product/2 -d '{"title" : "Another title"}'
curl -XPOST localhost:9200/test/product/3 -d '{"title" : "Shingles is a viral disease"}'
#Analyze API to check out shingling
curl -XGET 'localhost:9200/test/_analyze?analyzer=analyzer_shingle&pretty' -d 'Test text to see shingles' | grep token
#Sample search
curl -XGET 'localhost:9200/test/product/_search?q=title:product+title&pretty'
#this one won't return anything, because of the stop filter
curl -XGET 'localhost:9200/test/product/_search?q=title:is+a&pretty'
#while this one will, because we emit unigrams
curl -XGET 'localhost:9200/test/product/_search?q=title:is+a+viral&pretty'
@lancewalton
Copy link

I have the same question as renatalucia. Can we do fuzzy searches with this? How?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment