# User的mapping { "mappings": { "user": { "dynamic" : "strict", "properties": { "id": { "type": "string", "index": "not_analyzed" }, "name": { "type": "string", "index_analyzer": "ik", "search_analyzer": "ik_smart" }, "age": { "type": "integer" }, "job": { "type": "string", "index_analyzer": "ik", "search_analyzer": "ik_smart" }, "createTime": { "type": "long" } } } } } # 尝试创建user索引 $ curl -XPOST 'http://127.0.0.1:9200/user?pretty' -d '{ "mappings": { "user": { "dynamic" : "strict", "properties": { "id": { "type": "string", "index": "not_analyzed" }, "name": { "type": "string", "index_analyzer": "ik", "search_analyzer": "ik_smart" }, "age": { "type": "integer" }, "job": { "type": "string", "index_analyzer": "ik", "search_analyzer": "ik_smart" }, "createTime": { "type": "long" } } } } }' # 注意执行curl命令时,如果遇到下面的错误,原因是${ES_HOME}/lib/下需要引入httpclient-4.5.jar, httpcore-4.4.1.jar { "error" : "IndexCreationException[[user] failed to create index]; nested: NoClassDefFoundError[org/apache/http/client/ClientProtocolException]; nested: ClassNotFoundException[org.apache.http.client.ClientProtocolException]; ", "status" : 500 } # 创建索引成功后,查看索引信息 $ curl -XGET 'http://127.0.0.1:9200/_cat/indices?pretty' green open user 5 1 0 0 970b 575b # 测试standard分词效果 $ curl -XGET 'http://127.0.0.1:9200/user/_analyze?analyzer= standard&pretty=true' -d '{"text":"中华人民共和国国歌"}' # 测试ik分词效果 $ curl -XGET 'http://127.0.0.1:9200/user/_analyze?analyzer=ik&pretty=true' -d '{"text":"中华人民共和国国歌"}' # 测试ik_smart分词效果 $ curl -XGET 'http://127.0.0.1:9200/user/_analyze?analyzer=ik_smart&pretty=true' -d '{"text":"中华人民共和国国歌"}'
|