ik分词器插件,直接下载releases版本到plugin后解压,重启es生效
https://github.com/medcl/elasticsearch-analysis-ik/releases
$ curl -XPUT -H 'content-Type:application/json' 'http://localhost:9200/spu_v2' -d '
{
"settings": {
"number_of_shards": "3",
"number_of_replicas": "1",
"analysis": {
"filter": {
"share_synonym": {
"type": "synonym",
"synonyms_path": "synonym/share_synonym.txt"
},
"share_stopwords": {
"type": "stop",
"stopwords_path": "stopwords/share_stopwords.txt"
}
},
"analyzer": {
"ik_analyzer": {
"filter": [
"share_stopwords",
"share_synonym"
],
"char_filter": "html_strip",
"type": "custom",
"tokenizer": "ik_max_word"
}
},
"keyword_analyzer": {
"filter": [
"asciifolding",
"share_stopwords",
"share_synonym"
],
"char_filter": "html_strip",
"type": "custom",
"tokenizer": "keyword"
}
}
}
}'
$ curl -XGET 'localhost:9200/spu_v2/_settings?pretty'
$ curl -XPOST 'localhost:9200/spu_v2/_close'
$ curl -XPUT -H 'content-Type:application/json' 'http://localhost:9200/spu_v2/_settings' -d '
{
"settings": {
"analysis": {
"filter": {
"share_synonym": {
"type": "synonym",
"synonyms_path": "synonym/share_synonym.txt"
},
"share_stopwords": {
"type": "stop",
"stopwords_path": "stopwords/share_stopwords.txt"
}
},
"analyzer": {
"ik_analyzer": {
"filter": [
"asciifolding",
"share_stopwords",
"share_synonym"
],
"char_filter": "html_strip",
"type": "custom",
"tokenizer": "ik_max_word"
}
},
"keyword_analyzer": {
"filter": [
"asciifolding",
"share_stopwords",
"share_synonym"
],
"char_filter": "html_strip",
"type": "custom",
"tokenizer": "keyword"
}
}
}
}'
$ curl -XPOST 'localhost:9200/spu_v2/_open'
$ curl -XPOST -H 'content-Type:application/json' 'http://localhost:9200/spu_v2/_mapping' -d '
{
"dynamic": "strict",
"properties": {
"id": {
"type": "integer"
},
"goods_name": {
"type": "text",
"analyzer": "ik_analyzer",
"search_analyzer": "ik_analyzer"
},
"cat_id": {
"type": "short"
},
"cat_name": {
"type": "text",
"analyzer": "ik_analyzer",
"search_analyzer": "ik_analyzer"
},
"brand_id": {
"type": "integer"
},
"brand_name": {
"type": "text",
"analyzer": "ik_analyzer",
"search_analyzer": "ik_analyzer"
},
"created_at": {
"type": "integer"
},
"updated_at": {
"type": "integer"
}
}
}'
curl -XPOST -H 'content-Type:application/json' 'http://localhost:9200/_reindex?pretty' -d '
{
"source": {
"index": "spu_v1"
},
"dest": {
"index": "spu_v2"
}
}'
curl -XPOST -H 'content-Type:application/json' 'http://localhost:9200/_reindex?pretty' -d '
{
"source": {
"index": "spu_v1",
"_source":["brand_id","brand_name","cat_id","cat_name","created_at","updated_at"]
},
"dest": {
"index": "spu_v2"
}
}'
$ curl -XPOST -H 'content-Type:application/json' 'http://localhost:9200/_aliases' -d '
{
"actions": [
{
"remove": {
"index": "spu_v1",
"alias": "spu"
}
},
{
"add": {
"index": "spu_v2",
"alias": "spu"
}
}
]
}'
$ curl -XDELETE 'http://localhost:9200/spu_v1'
$ curl -XGET -H 'content-Type:application/json' 'http://localhost:9200/spu_v2/_analyze' -d '
{
"analyzer": "ik_analyzer",
"text": "六味地黄丸软胶囊"
}'
$ curl -XGET 'http://10.180.18.30:9200/spu_v2/_doc/_count'
$ curl -XGET 'http://10.180.18.30:9200/spu_v2/_search'
$ curl -XGET 'http://10.180.18.30:9200/spu_v2/_doc/659'
$ curl -XGET -H 'content-Type:application/json' 'http://localhost:9200/spu_v2/_doc/_search?pretty' -d '
{
"query": {
"match": {
"goods_name": "兰蔻"
}
}
}'
$ curl -XDELETE -H 'content-Type:application/json' 'http://localhost:9200/spu_v2/_doc/20'
$ curl -XPUT -H 'content-Type:application/json' 'http://localhost:9200/spu_v2/_mapping' -d '
{
"properties": {
"support_sell": {
"type": "byte"
},
"weights": {
"type": "integer"
}
}
}'
> 全部更新
$ curl -XPOST -H 'content-Type:application/json' 'http://localhost:9200/spu_v2/_doc/_update_by_query' -d '
{
"script": {
"source": "ctx._source.support_sell = 0"
}
}'
> 使用带搜索条件的批量操作
$ curl -XPOST -H 'content-Type:application/json' 'http://localhost:9200/spu_v2/_doc/_update_by_query' -d '
{
"query": {
"bool": {
"must": {
"terms": {"id": [26, 43]}
}
}
},
"script": {
"source": "ctx._source.support_sell = 0"
}
}'
$ curl -XPOST -H 'content-Type:application/json' 'http://localhost:9200/spu_v2/_doc/43/_update' -d '
{
"doc": {
"support_sell": "1",
"weights": "1"
}
}'
> 使用脚本更新单个文档的值
$ curl -XPOST -H 'content-Type:application/json' 'http://localhost:9200/spu_v2/_doc/43/_update' -d '
{
"script": {
"source": "ctx._source.support_sell = 0;ctx._source.weights = 0"
}
}'
> 脚本中传递参数
curl -XPOST -H 'content-Type:application/json' 'http://localhost:9200/spu_v2/_doc/43/_update' -d '
{
"script": {
"source": "ctx._source.support_sell = params.support_sell",
"params": {
"support_sell": 1
}
}
}'