Skip to content

Instantly share code, notes, and snippets.

@joecwu
Last active August 29, 2019 10:52
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 joecwu/0c7f5535ddf83bf8db512141556a9df8 to your computer and use it in GitHub Desktop.
Save joecwu/0c7f5535ddf83bf8db512141556a9df8 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ -z $1 ]; then
echo "usage: $0 APP_SEARCH_HOST APP_SEARCH_AUTH ES_HOST ENGINE_NAME"
exit 1
else
APP_SEARCH_HOST=$1
fi
if [ -z $2 ]; then
echo "usage: $0 APP_SEARCH_HOST APP_SEARCH_AUTH ES_HOST ENGINE_NAME"
exit 1
else
APP_SEARCH_AUTH=$2
fi
if [ -z $3 ]; then
echo "usage: $0 APP_SEARCH_HOST APP_SEARCH_AUTH ES_HOST ENGINE_NAME"
exit 1
else
ES_HOST=$3
fi
if [ -z $4 ]; then
echo "usage: $0 APP_SEARCH_HOST APP_SEARCH_AUTH ES_HOST ENGINE_NAME"
exit 1
else
ENGINE_NAME=$4
fi
echo "creating engine - $ENGINE_NAME on app-search:[$APP_SEARCH_HOST]"
curl -X POST "http://${APP_SEARCH_HOST}/api/as/v1/engines" \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ${APP_SEARCH_AUTH}" \
-d '{
"name": "'"${ENGINE_NAME}"'",
"language": "ja"
}'
echo ""
echo "extracting engine id"
ENGINE_ID=$(curl -X GET "http://${ES_HOST}/.app-search-actastic-engines_v2/_search?q=name:${ENGINE_NAME}&_source=id&filter_path=hits.hits._source" | sed 's/.*\"\(.*\)\".*/\1/')
echo "ENGINE_ID:[$ENGINE_ID]"
echo "indexing first document into engine:[${ENGINE_ID}]"
curl -X POST "http://${APP_SEARCH_HOST}/api/as/v1/engines/${ENGINE_NAME}/documents" \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ${APP_SEARCH_AUTH}" \
-d '[{
"id": 1
}]'
echo ""
echo "wait for 3 seconds..."
sleep 3
echo "deleting pre-gen engine index..."
curl -X DELETE "http://${ES_HOST}/.app-search-engine-${ENGINE_ID}"
echo ""
echo "re-generating engine index..."
curl -X PUT "http://${ES_HOST}/.app-search-engine-${ENGINE_ID}" \
-H 'Content-Type: application/json' \
-d '{"settings":{"index":{"search":{"slowlog":{"level":"debug","threshold":{"fetch":{"warn":"1000ms","trace":"200ms","debug":"300ms","info":"800ms"},"query":{"warn":"2000ms","trace":"500ms","debug":"1000ms","info":"1000ms"}}}},"indexing":{"slowlog":{"threshold":{"index":{"warn":"10s","trace":"500ms","debug":"2s","info":"5s"}}}},"number_of_shards":"2","auto_expand_replicas":"0-1","similarity":{"default":{"type":"BM25"}},"analysis":{"filter":{"front_ngram":{"type":"edge_ngram","min_gram":"1","max_gram":"12"},"bigram_joiner":{"max_shingle_size":"2","token_separator":"","output_unigrams":"false","type":"shingle"},"bigram_max_size":{"type":"length","max":"16","min":"0"},"phrase_shingle":{"max_shingle_size":"3","min_shingle_size":"2","output_unigrams":"true","type":"shingle"},"katakana_readingform":{"type":"kuromoji_readingform","use_romaji":"false"},"delimiter":{"split_on_numerics":"true","generate_word_parts":"true","preserve_original":"false","catenate_words":"true","generate_number_parts":"true","catenate_all":"true","split_on_case_change":"true","type":"word_delimiter_graph","catenate_numbers":"true","stem_english_possessive":"true"},"ja-stop-words-filter":{"type":"stop","stopwords":"_english_"},"ja-stem-filter":{"name":"light_english","type":"stemmer"},"single_gram":{"type":"ngram","min_gram":1,"max_gram":1}},"analyzer":{"i_prefix":{"filter":["cjk_width","lowercase","asciifolding","front_ngram"],"tokenizer":"standard"},"iq_intragram":{"filter":["cjk_width","lowercase","asciifolding"],"tokenizer":"intragram_tokenizer"},"iq_phrase_shingle":{"filter":["cjk_width","lowercase","asciifolding","phrase_shingle"],"tokenizer":"standard"},"iq_text_delimiter":{"filter":["delimiter","cjk_width","lowercase","asciifolding","ja-stop-words-filter","ja-stem-filter","cjk_bigram"],"tokenizer":"whitespace"},"q_prefix":{"filter":["cjk_width","lowercase","asciifolding"],"tokenizer":"standard"},"iq_text_base":{"filter":["cjk_width","lowercase","kuromoji_stemmer","ja_stop","katakana_readingform"],"mode":"search","tokenizer":"kuromoji_tokenizer"},"iq_text_stem":{"filter":["cjk_width","lowercase","asciifolding","ja-stop-words-filter","ja-stem-filter","cjk_bigram"],"tokenizer":"standard"},"iq_text_bigram":{"filter":["kuromoji_stemmer","ja_stop","katakana_readingform","cjk_width","lowercase","asciifolding","single_gram","bigram_joiner","bigram_max_size"],"tokenizer":"kuromoji_tokenizer"}},"tokenizer":{"intragram_tokenizer":{"token_chars":["letter","digit"],"min_gram":"3","type":"ngram","max_gram":"4"}}},"number_of_replicas":"0"}},"mappings":{"dynamic":"strict","properties":{"__st_expires_after":{"type":"date"},"__st_text_summary":{"type":"text","analyzer":"iq_phrase_shingle"},"engine_id":{"type":"keyword"},"external_id":{"type":"keyword"},"id":{"type":"keyword"}}}}'
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment