post 新增
get 查詢
put更新
post http://127.0.0.1:9200/index4/type1
{"node":0}
{
"_index": "index4",
"_type": "type1",
"_id": "W_WMOHYBA6aNNN1EWEI0",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 0,
"_primary_term": 1
}
查詢:
http://127.0.0.1:9200/index4/type1/_search
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 2,
"relation": "eq"
},
"max_score": 1.0,
"hits": [
{
"_index": "index4",
"_type": "type1",
"_id": "W_WMOHYBA6aNNN1EWEI0",
"_score": 1.0,
"_source": {
"node": 0
}
},
{
"_index": "index4",
"_type": "type1",
"_id": "XPWROHYBA6aNNN1EL0Ig",
"_score": 1.0,
"_source": {
"node": 0,
"age": 3
}
}
]
}
}
剛學有點懵懵的....
之前安裝了es的ik分詞器,繼續試試...
IK分詞效果有兩種,一種是ik_max_word(最大分詞)和ik_smart(最小分詞)
post http://127.0.0.1:9200/_analyze
請求參數
{
"analyzer":"ik_smart",
"text":"中國abc"
}
返回
{
"tokens": [
{
"token": "中國abc",
"start_offset": 0,
"end_offset": 5,
"type": "CN_WORD",
"position": 0
}
]
}
如果是最細力度划分:
請求
{
"analyzer":"ik_max_word",
"text":"中國abc"
}
返回:
{
"tokens": [
{
"token": "中國",
"start_offset": 0,
"end_offset": 2,
"type": "CN_WORD",
"position": 0
},
{
"token": "abc",
"start_offset": 2,
"end_offset": 5,
"type": "ENGLISH",
"position": 1
}
]
}
如果有些詞我們不想拆看怎么辦,配置自己的分詞配置:
打開ik/config/IKAnalyzer.cfg.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> <comment>IK Analyzer 擴展配置</comment> <!--用戶可以在這里配置自己的擴展字典 --> <entry key="ext_dict">player3.dic</entry> <!--用戶可以在這里配置自己的擴展停止詞字典--> <entry key="ext_stopwords"></entry> <!--用戶可以在這里配置遠程擴展字典 --> <!-- <entry key="remote_ext_dict">words_location</entry> --> <!--用戶可以在這里配置遠程擴展停止詞字典--> <!-- <entry key="remote_ext_stopwords">words_location</entry> --> </properties>
新建player3.dic文件,寫入自己的分詞配置

重啟es項目

加載自己的配置文件
{
"analyzer":"ik_smart",
"text":"我非常喜歡三號小玩家他的網民player3是我喜歡的類型"
}
{
"tokens": [
{
"token": "我",
"start_offset": 0,
"end_offset": 1,
"type": "CN_CHAR",
"position": 0
},
{
"token": "非常",
"start_offset": 1,
"end_offset": 3,
"type": "CN_WORD",
"position": 1
},
{
"token": "喜歡",
"start_offset": 3,
"end_offset": 5,
"type": "CN_WORD",
"position": 2
},
{
"token": "三號小玩家",
"start_offset": 5,
"end_offset": 10,
"type": "CN_WORD",
"position": 3
},
{
"token": "他",
"start_offset": 10,
"end_offset": 11,
"type": "CN_CHAR",
"position": 4
},
{
"token": "的",
"start_offset": 11,
"end_offset": 12,
"type": "CN_CHAR",
"position": 5
},
{
"token": "網民",
"start_offset": 12,
"end_offset": 14,
"type": "CN_WORD",
"position": 6
},
{
"token": "player3",
"start_offset": 14,
"end_offset": 21,
"type": "CN_WORD",
"position": 7
},
{
"token": "是",
"start_offset": 21,
"end_offset": 22,
"type": "CN_CHAR",
"position": 8
},
{
"token": "我",
"start_offset": 22,
"end_offset": 23,
"type": "CN_CHAR",
"position": 9
},
{
"token": "喜歡",
"start_offset": 23,
"end_offset": 25,
"type": "CN_WORD",
"position": 10
},
{
"token": "的",
"start_offset": 25,
"end_offset": 26,
"type": "CN_CHAR",
"position": 11
},
{
"token": "類型",
"start_offset": 26,
"end_offset": 28,
"type": "CN_WORD",
"position": 12
}
]
}
ok啦
