Skip to content

Instantly share code, notes, and snippets.

@GarKoZ
Created November 16, 2018 06:54
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 GarKoZ/6f640601c198e1164d8793c7452966e2 to your computer and use it in GitHub Desktop.
Save GarKoZ/6f640601c198e1164d8793c7452966e2 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Tested with elasticsearch version 6.1.3
# Using ICU Analysis plugin, otherwise replace icu_tokenizer with thai in mapping part
# Delete the existed one
curl -XDELETE localhost:9200/test?pretty
# Put new mapping
curl -XPUT localhost:9200/test?pretty -H 'Content-Type: application/json' -d '{
"settings": {
"index": {
"analysis": {
"analyzer": {
"analyzer_shingle": {
"tokenizer": "icu_tokenizer",
"filter": [
"filter_shingle"
]
}
},
"filter": {
"filter_shingle": {
"type": "shingle",
"max_shingle_size": 3,
"min_shingle_size": 2,
"output_unigrams": "true"
}
}
}
}
},
"mappings": {
"product": {
"properties": {
"content": {
"analyzer": "analyzer_shingle",
"type": "text"
}
}
}
}
}'
# Add some docs to the index
curl -H 'Content-Type: application/json' -XPOST localhost:9200/test/product/1?pretty -d '{"content" : "ฉันจะไปกินข้าวมันไก่"}'
curl -H 'Content-Type: application/json' -XPOST localhost:9200/test/product/2?pretty -d '{"content" : "ไก่ย่างถูกเผา มันจะถูกไม้เสียบ"}'
curl -H 'Content-Type: application/json' -XPOST localhost:9200/test/product/3?pretty -d '{"content" : "เสียบปีกซ้าย เสียบปีกขวา"}'
# Take some time before content can be search after post
sleep 4
# Analyze API to check out shingling
curl -H 'Content-Type: application/json' -XGET localhost:9200/test/_analyze?pretty -d '{ "analyzer": "analyzer_shingle", "text":"ข้าวมันไก่ ไก่ย่างถูกเผา"}' | grep "token"
# Check ranking from query with difference keyword
curl -H 'Content-Type: application/json' -XPOST localhost:9200/test/product/_search?pretty -d '{"query" : {"match" : {"content" : "มันไก่"}}}' | grep -E "content|score"
curl -H 'Content-Type: application/json' -XPOST localhost:9200/test/product/_search?pretty -d '{"query" : {"match" : {"content" : "ไก่มัน"}}}' | grep -E "content|score"
curl -H 'Content-Type: application/json' -XPOST localhost:9200/test/product/_search?pretty -d '{"query" : {"match" : {"content" : "ข้าวมันไก่"}}}' | grep -E "content|score"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment