Skip to content

Instantly share code, notes, and snippets.

@herrvonb
Last active August 29, 2015 14:07
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 herrvonb/0a247aa7dfd0d155b418 to your computer and use it in GitHub Desktop.
Save herrvonb/0a247aa7dfd0d155b418 to your computer and use it in GitHub Desktop.
Creating new elasticsearch index, with custom analyzer: stemming dutch compound words, finally run query
#!/bin/bash
curl -XDELETE localhost:9200/foo
curl -XPUT localhost:9200/foo -d '{
"settings": {
"number_of_replicas": 0,
"number_of_shards": 1,
"analysis": {
"filter": {
"dutch_stemmer": {
"type": "dictionary_decompounder",
"word_list": [
"koud",
"plaat",
"staal",
"fabriek"
]
},
"snowball_nl": {
"type": "snowball",
"language": "dutch"
}
},
"analyzer": {
"dutch": {
"tokenizer": "standard",
"filter": [
"length",
"lowercase",
"asciifolding",
"dutch_stemmer",
"snowball_nl"
]
}
}
}
}
}'
curl -XPOST localhost:9200/foo/bar/_mapping -d '{
"properties": {
"test": {
"type": "string",
"analyzer": "dutch"
}
}
}'
# adding some document
curl -XPOST localhost:9200/foo/bar/_bulk -d '
{"index": {"_id":"1"}}
{"test": "ijskoud"}
{"index": {"_id":"2"}}
{"test": "plaatstaal"}
{"index": {"_id":"3"}}
{"test": "kristalfabriek"}
'
# dont search to early as es needs some time until docs a available
sleep 1
printf "\nall documents:\n"
curl -XGET localhost:9200/foo/_search?pretty=true
printf "\nactive mapping\n"
curl -XGET localhost:9200/foo/_mapping?pretty=true
printf "\nsearch for plaat\n"
curl -XGET localhost:9200/foo/_search?pretty=true -d '{
"query": {
"match": {
"test": "plaat"
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment