Elasticsearch demo

Create a new index

1
2
3
curl -XDELETE http://192.168.3.11:9200/policy

curl -XPUT http://192.168.3.11:9200/policy

A new field mapping

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
curl -XPOST http://192.168.3.11:9200/policy/fulltext/_mapping -d'
{
"fulltext": {
"_all": {
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word",
"term_vector": "no",
"store": "false"
},
"properties": {
"content": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word",
"include_in_all": "true",
"boost": 8
}
}
}
}'

Add data

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
curl -XPOST http://192.168.3.11:9200/policy/fulltext/1 -d'
{"content":"2017年1月1日起全国实行国Ⅴ排放标准"}
'
curl -XPOST http://192.168.3.11:9200/policy/fulltext/2 -d'
{"content":"2017年1月1日起实施:车内空气质量强制达标"}
'
curl -XPOST http://192.168.3.11:9200/policy/fulltext/3 -d'
{"content":"2017年试行新能源汽车碳配额管理"}
'
curl -XPOST http://192.168.3.11:9200/policy/fulltext/4 -d'
{"content":"新能源车生产企业准入规则 有望于2017年正式实施"}
'
curl -XPOST http://192.168.3.11:9200/policy/fulltext/5 -d'
{"content":"电池行业新规范 有望于2017年全面执行"}
'
curl -XPOST http://192.168.3.11:9200/policy/fulltext/6 -d'
{"content":"新能源补贴新政即将出炉 2017年将实施"}
'
curl -XPOST http://192.168.3.11:9200/policy/fulltext/7 -d'
{"content":"《外商投资产业指导目录》修订版将执行 合资车企股比不会放开"}
'
1
2
3
4
5
6
7
8
9
10
11
12
curl -XPOST http://192.168.3.11:9200/policy/fulltext/_search  -d'
{
"query" : { "match" : { "content" : "能源" }},
"highlight" : {
"pre_tags" : ["<tag1>", "<tag2>"],
"post_tags" : ["</tag1>", "</tag2>"],
"fields" : {
"content" : {}
}
}
}
'

Check engine status

1
2
3
curl -XGET http://192.168.3.11:9200/policy/_analyze?text=2017&tokenizer=ik_max_word

curl -XGET http://192.168.3.11:9200/_cluster/health?pretty=true