Skip to content

Instantly share code, notes, and snippets.

@imotov
Created November 13, 2012 21:53
Show Gist options
  • Save imotov/73fcd9f3e19165802e14 to your computer and use it in GitHub Desktop.
Save imotov/73fcd9f3e19165802e14 to your computer and use it in GitHub Desktop.
shingles
curl -XDELETE localhost:9200/shingles
echo
curl -XPUT localhost:9200/shingles -d '{
"mappings": {
"post": {
"properties": {
"body": {
"fields": {
"body": {
"type": "string",
"analyzer": "analyzer_term"
},
"partial_shingle": {
"search_analyzer": "analyzer_term",
"index_analyzer": "analyzer_partial_shingle",
"type": "string"
}
},
"type": "multi_field"
}
}
}
},
"settings": {
"index.number_of_shards": 1,
"index.number_of_replicas": 0,
"analysis": {
"filter": {
"filter_partial_shingle": {
"type": "shingle",
"max_shingle_size": 5,
"min_shingle_size": 2,
"output_unigrams": "false"
}
},
"analyzer": {
"analyzer_term": {
"filter": ["lowercase", "asciifolding"],
"type": "custom",
"tokenizer": "whitespace"
},
"analyzer_partial_shingle": {
"filter": ["lowercase", "asciifolding", "filter_partial_shingle"],
"type": "custom",
"tokenizer": "whitespace"
}
}
}
}
}
'
echo
curl -XPUT localhost:9200/shingles/post/1 -d '{
"body": "Great Planes Rotor Blade"
}'
echo
curl -XPOST localhost:9200/shingles/_refresh
echo
curl "localhost:9200/shingles/post/_search?pretty=true" -d '{
"query": {
"match_phrase": {
"body.partial_shingle": {
"query": "Great Planes Rotor Blade",
"analyzer": "analyzer_partial_shingle"
}
}
}
}
'
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment