Elasticsearch-5.1.2分词器IK+pinyin简单测试
生活随笔
收集整理的這篇文章主要介紹了
Elasticsearch-5.1.2分词器IK+pinyin简单测试
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
前提是ik和pinyin分詞器都安裝好了,并運行正常,請參考前面兩篇
elasticsearch-5.1.2安裝IK分詞器并測試
elasticsearch-5.1.2安裝pinyin分詞器并測試
創建一個索引,并設置index分析器相關屬性
[listen@localhost elasticsearch-cluster]$ curl -XPUT 'http://192.168.159.129:9201/ikpinyinindex/?pretty' -d ' > { > "index": { > "analysis": { > "analyzer": { > "ik_pinyin_analyzer":{ > "type": "custom", > "tokenizer": "ik_smart", > "filter": ["my_pinyin", "word_delimiter"] > } > }, > "filter": { > "my_pinyin": { > "type": "pinyin", > "first_letter": "prefix", > "padding_char": " " > } > } > } > } > }' {"acknowledged" : true,"shards_acknowledged" : true } [listen@localhost elasticsearch-cluster]$創建一個type并設置mapping
[listen@localhost elasticsearch-cluster]$ curl -XPUT 'http://192.168.159.129:9201/ikpinyinindex/folks/_mapping/?pretty' -d ' > { > "folks":{ > "properties": { > "name": { > "type": "keyword", > "fields": { > "pinyin": { > "type": "text", > "store": "no", > "term_vector": "with_positions_offsets", > "analyzer": "ik_pinyin_analyzer", > "boost": 10 > } > } > } > } > } > }' {"acknowledged" : true } [listen@localhost elasticsearch-cluster]$插入2條記錄
[listen@localhost elasticsearch-cluster]$ curl -XPOST 'http://192.168.159.129:9201/ikpinyinindex/folks/andy/?pretty' -d '{"name": "劉德華"}' {"_index" : "ikpinyinindex","_type" : "folks","_id" : "andy","_version" : 1,"result" : "created","_shards" : {"total" : 2,"successful" : 1,"failed" : 0},"created" : true } [listen@localhost elasticsearch-cluster]$ [listen@localhost elasticsearch-cluster]$ curl -XPOST 'http://192.168.159.129:9201/ikpinyinindex/folks/tina/?pretty' -d '{"name": "中華人民共和國國歌"}' {"_index" : "ikpinyinindex","_type" : "folks","_id" : "tina","_version" : 1,"result" : "created","_shards" : {"total" : 2,"successful" : 1,"failed" : 0},"created" : true } [listen@localhost elasticsearch-cluster]$測試
[listen@localhost elasticsearch-cluster]$ curl -XPOST 'http://192.168.159.129:9201/ikpinyinindex/_search/?pretty' -d ' > { > "query":{ > "match":{ > "name.pinyin": "zhonghua" > } > }, > "highlight":{ > "fields": { > "name.pinyin": {} > } > } > }' {"took" : 74,"timed_out" : false,"_shards" : {"total" : 5,"successful" : 5,"failed" : 0},"hits" : {"total" : 2,"max_score" : 5.9814634,"hits" : [{"_index" : "ikpinyinindex","_type" : "folks","_id" : "tina","_score" : 5.9814634,"_source" : {"name" : "中華人民共和國國歌"},"highlight" : {"name.pinyin" : ["<em>中華人民共和國</em>國歌"]}},{"_index" : "ikpinyinindex","_type" : "folks","_id" : "andy","_score" : 2.2534127,"_source" : {"name" : "劉德華"},"highlight" : {"name.pinyin" : ["<em>劉德華</em>"]}}]} } [listen@localhost elasticsearch-cluster]$錯誤的寫法,返回結果為空
[listen@localhost elasticsearch-cluster]$ curl -XPOST 'http://192.168.159.129:9201/ikpinyinindex/_search/?pretty' -d ' {"query":{"match":{"name": "中華"}},"highlight":{"fields": {"name.pinyin": {}}} }' {"took" : 18,"timed_out" : false,"_shards" : {"total" : 5,"successful" : 5,"failed" : 0},"hits" : {"total" : 0,"max_score" : null,"hits" : [ ]} } [listen@localhost elasticsearch-cluster]$?
轉載于:https://my.oschina.net/Listening/blog/828566
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的Elasticsearch-5.1.2分词器IK+pinyin简单测试的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java随机输出10计算题
- 下一篇: 几个 Python 语法糖的实现