创建自定义分词器:
url = "http://ip:port/index/_settings"
res = requests.put(url, json={
"settings": {
"analysis": {
"analyzer": {
"comma": {
"type": "pattern",
"pattern":","
}
}
}
}
}
)
使用分词器:
url = "http://ip:port/index/_mapping/type"
resp = requests.put(url, json={
"properties": {
"title": {
"type": "text",
"analyzer": "ik_smart",
"search_analyzer": "ik_smart"
},
"content": {
"type": "text",
"analyzer": "comma",
"search_analyzer": "comma",
},
}
})
index:索引名称(库)
comma:自定义分词器名称
type:类型(表)