-
-
Save imotov/3ba124fdd4b0db5d0219 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# Удаляем тестовый индекс | |
curl -X DELETE "http://localhost:9200/test-index" | |
echo | |
# Создаем индекс | |
curl -X PUT "http://localhost:9200/test-index" -d ' | |
{ | |
"settings": { | |
"index": { | |
"number_of_shards": 5, | |
"number_of_replicas": 0, | |
"analysis": { | |
"analyzer": { | |
"pa_prefix_analyzer": { | |
"tokenizer": "pa_prefix_tokenizer", | |
"filter": ["lowercase", "word_delimiter"], | |
"char_filter" : ["ru_chars_mapping"] | |
}, | |
"pa_prefix_analyzer_search": { | |
"tokenizer": "keyword", | |
"filter": ["lowercase", "word_delimiter"], | |
"char_filter" : ["ru_chars_mapping"] | |
} | |
}, | |
"char_filter" : { | |
"ru_chars_mapping" : { | |
"type" : "mapping", | |
"mappings" : ["ё=>е"] | |
} | |
}, | |
"tokenizer": { | |
"pa_prefix_tokenizer": { | |
"type" : "edgeNGram", | |
"min_gram" : "1", | |
"max_gram" : "20", | |
"token_chars": [ "letter", "digit" ] | |
} | |
} | |
} | |
} | |
} | |
}' | |
echo | |
# Создаем меппинг | |
curl -X PUT "http://localhost:9200/test-index/test1/_mapping?pretty=true" -d ' | |
{ | |
"test1": { | |
"properties": { | |
"street": { | |
"properties": { | |
"name": { | |
"type": "string", | |
"fields": { | |
"prefix": { | |
"type": "string", | |
"index_analyzer": "pa_prefix_analyzer", | |
"search_analyzer": "pa_prefix_analyzer_search", | |
"norms": { | |
"enabled": false | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
}' | |
echo | |
# Создаем тестовые записи | |
curl -X POST "http://localhost:9200/test-index/test1/1" -d "{ \"street\": {\"name\" : \"Молотов\"}}" | |
curl -X POST "http://localhost:9200/test-index/test1/2" -d "{ \"street\": {\"name\" : \"Мурманск\"}}" | |
curl -X POST "http://localhost:9200/test-index/test1/3" -d "{ \"street\": {\"name\" : \"Москва\"}}" | |
curl -X POST "http://localhost:9200/test-index/test1/4" -d "{ \"street\": {\"name\" : \"Большое Море\"}}" | |
# Обновляем | |
curl -X POST "http://localhost:9200/test-index/_refresh" | |
# Выборка | |
echo | |
echo | |
curl -X POST "http://localhost:9200/test-index/test1/_search?pretty=true" -d ' | |
{ | |
"explain": false, | |
"query": { | |
"match": { | |
"street.name.prefix": { | |
"query": "мос" | |
} | |
} | |
} | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment