我的ES中有一批“智能手机”产品,我需要使用“智能手机”文本来查询它们。因此,我正在研究复合词标记过滤器。具体来说,我计划使用这样的自定义过滤器:
curl -XPUT 'localhost:9200/_all/_settings -d '
{
"analysis" : {
"analyzer":{
"second":{
"type":"custom",
"tokenizer":"standard",
"filter":["myFilter"]
}
"filter": {
"myFilter" :{
"type" : "dictionary_decompounder"
"word_list": ["smart", "phone"]
}
}
}
}
}
'
这是正确的做法吗?另外,我想问您如何创建自定义分析器并将其添加到ES中?我查了几个链接,但不知道怎么做。我想我是在寻找正确的语法。谢谢
编辑
我正在运行1.4.5版本。我验证了自定义分析器是成功添加的:
{
"test_index" : {
"settings" : {
"index" : {
"creation_date" : "1453761455612",
"analysis" : {
"filter" : {
"myFilter" : {
"type" : "dictionary_decompounder",
"word_list" : [ "smart", "phone" ]
}
},
"analyzer" : {
"second" : {
"type" : "custom",
"filter" : [ "lowercase", "myFilter" ],
"tokenizer" : "standard"
}
}
},
"number_of_shards" : "5",
"number_of_replicas" : "1",
"version" : {
"created" : "1040599"
},
"uuid" : "xooKEdMBR260dnWYGN_ZQA"
}
}
}
}
发布于 2016-01-24 23:13:25
你的方法看起来不错,我也会考虑加入小写令牌过滤器,这样即使是智能手机(注意大写“S”)也会被分成智能手机和手机。
然后你可以用这样的分析器创建索引,
curl -XPUT 'localhost:9200/your_index -d '
{
"settings": {
"analysis": {
"analyzer": {
"second": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"myFilter"
]
}
},
"filter": {
"myFilter": {
"type": "dictionary_decompounder",
"word_list": [
"smart",
"phone"
]
}
}
}
},
"mappings": {
"my_type": {
"properties": {
"name": {
"type": "string",
"analyzer": "second"
}
}
}
}
}
'
在这里,您将创建名为your_index的索引,custom analyzer
命名为second,并将其应用于name字段。
您可以检查分析器是否像预期的那样与分析api一起工作
curl -XGET 'localhost:9200/your_index/_analyze' -d '
{
"analyzer" : "second",
"text" : "LG Android smartphone"
}'
希望这能帮上忙!
https://stackoverflow.com/questions/34982445
复制相似问题