Skip to content

Instantly share code, notes, and snippets.

@xueruini
Created November 2, 2017 10:59
Show Gist options
  • Save xueruini/4fb006c6f4cdf1af32cc621945187583 to your computer and use it in GitHub Desktop.
Save xueruini/4fb006c6f4cdf1af32cc621945187583 to your computer and use it in GitHub Desktop.
search
HOST=http://elasticsearch.dev-id.internal.hyku.org:9200
# drop index
curl -XDELETE $HOST/my_index
# create index
curl -XPUT $HOST/my_index -d '{
"settings":{
"analysis":{
"analyzer":{
"my_ngram_analyzer":{
"tokenizer":"my_ngram_tokenizer"
},
"my_punctuation_analyzer": {
"type": "custom",
"tokenizer": "punctuation",
"filter": [
"lowercase",
"stop"
]
}
},
"tokenizer":{
"punctuation": {
"type": "pattern",
"pattern": "[ .,!?-]"
},
"my_ngram_tokenizer":{
"type":"nGram",
"min_gram": 1,
"max_gram": 14,
"token_chars":[
"letter",
"digit"
]
}
}
}
}
}'
# create table items
curl -XPUT $HOST/my_index/_mapping/items -d '{
"items":{
"properties":{
"id":{
"analyzer":"my_ngram_analyzer",
"search_analyzer":"my_punctuation_analyzer",
"type":"text"
}
}
}
}'
# create data
curl -XPUT $HOST/my_index/items/1 -d '{"id": "86-1344675中国"}'
curl -XPUT $HOST/my_index/items/2 -d '{"id": "Red86-1344675中国"}'
curl -XPUT $HOST/my_index/items/3 -d '{"id": "Red Great 中"}'
curl -XPUT $HOST/my_index/items/4 -d '{"id": "1133"}'
# query
http POST $HOST/my_index/items/_search Content-type:application/json < a.json
@xueruini
Copy link
Author

xueruini commented Nov 2, 2017

{
	"query": {
		"match": {
			"id": { "query":"86-中国"}
		}
    },
     "highlight" : {
        "fields" : {
            "id" : {}
        }
	}
}

@xueruini
Copy link
Author

xueruini commented Nov 2, 2017

HOST=http://elasticsearch.dev-id.internal.hyku.org:9200

# drop index

curl -XDELETE $HOST/my_index

# create index
curl -XPUT $HOST/my_index -d '{
  "settings":{
    "analysis":{
      "analyzer":{
        "my_ngram_analyzer":{
          "tokenizer":"my_ngram_tokenizer"
        },
        "my_punctuation_analyzer": {
          "type": "custom",
          "tokenizer": "punctuation", 
          "filter": [
            "lowercase",
            "stop" 
          ]
        }
      },
      "tokenizer":{
        "punctuation": {
          "type": "pattern",
          "pattern": "\\p{Punct}|\\h"
        },
        "my_ngram_tokenizer":{
          "type":"nGram",
          "min_gram": 1,
          "max_gram": 14,
          "token_chars":[
            "letter",
            "digit"
          ]
        }
      }
    }
  }
}'

# create table items
curl -XPUT $HOST/my_index/_mapping/items -d '{
  "items":{
    "properties":{
      "id":{
        "analyzer":"my_ngram_analyzer",
        "search_analyzer":"my_punctuation_analyzer",
        "type":"text"
      }
    }
  }
}'

# create data

curl -XPUT $HOST/my_index/items/1 -d '{"id": "86-1344675中国"}'
curl -XPUT $HOST/my_index/items/2 -d '{"id": "Red86-1344675中国"}'
curl -XPUT $HOST/my_index/items/3 -d '{"id": "Red Great 中"}'
curl -XPUT $HOST/my_index/items/4 -d '{"id": "1133"}'

# query

http POST $HOST/my_index/items/_search  Content-type:application/json < a.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment