Skip to content

Instantly share code, notes, and snippets.

@hgminh95
Forked from polyfractal/gist:4542494
Last active May 9, 2016 04:31
Show Gist options
  • Save hgminh95/525a00360b714328758007604d7c45e3 to your computer and use it in GitHub Desktop.
Save hgminh95/525a00360b714328758007604d7c45e3 to your computer and use it in GitHub Desktop.
curl -XDELETE localhost:9200/test
#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_shingle"]
}
},
"filter":{
"filter_shingle":{
"type":"shingle",
"max_shingle_size":6,
"min_shingle_size":2,
"output_unigrams":"true"
}
}
}
}
},
"mappings":{
"article":{
"properties":{
"content":{
"analyzer":"analyzer_shingle",
"type":"string"
}
}
}
}
}'
#Add some docs to the index
curl -XPOST localhost:9200/test/article/1 -d '{"content" : "Sample product title for shingles"}'
curl -XPOST localhost:9200/test/article/2 -d '{"content" : "Another title"}'
curl -XPOST localhost:9200/test/article/3 -d '{"content" : "Shingles is a viral disease"}'
#Analyze API to check out shingling
curl -XGET 'localhost:9200/test/_analyze?analyzer=analyzer_shingle&pretty' -d 'Shingles is a viral disease' | grep token
curl -XGET 'localhost:9200/test/article/_search?pretty=true' -d '{
"query": {
"term": {
"content": "viral disease"
}
}
}'
curl -XGET 'localhost:9200/test/article/_search?pretty=true' -d '{
"query": {
"terms": {
"content": ["viral disease", "sample product"]
}
}
}'
curl -XGET 'localhost:9200/test/article/_search?pretty=true' -d '{
"query": {
"bool": {
"must": {
"terms": {
"content": ["viral disease", "sample product"]
}
},
"must": {
"terms": {
"content": ["title"]
}
}
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment