gpt4 book ai didi

elasticsearch - 如何在Elasticsearch中创建和添加自定义分析器?

转载 作者:行者123 更新时间:2023-12-03 00:42:08 27 4
gpt4 key购买 nike

我的ES中有一批“智能手机”产品,我需要使用“智能手机”文本进行查询。因此,我正在研究复合词 token 过滤器。具体来说,我打算使用这样的自定义过滤器:

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"
}
}
}
}

最佳答案

您的方法看起来不错,我也将考虑添加lowercase token filter,这样即使是智能手机(注意大写的“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的索引,名为second的 custom analyzer并将其应用于名称字段。

您可以像这样使用 analyze api检查分析仪是否按预期工作
curl -XGET 'localhost:9200/your_index/_analyze' -d '
{
"analyzer" : "second",
"text" : "LG Android smartphone"
}'

希望这可以帮助!!

关于elasticsearch - 如何在Elasticsearch中创建和添加自定义分析器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34982445/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com