gpt4 book ai didi

elasticsearch - Elasticsearch :对同一数据运行多个分析器

转载 作者:行者123 更新时间:2023-12-02 22:57:27 26 4
gpt4 key购买 nike

我正在寻找一种使ES使用多个分析仪搜索数据的方法。
NGram分析器和一种或几种语言分析器。

可能的解决方案是使用多字段并显式声明要为每个字段使用哪个分析器。

例如,设置以下映射:

  "mappings": {
"my_entity": {
"properties": {
"my_field": {
"type": "text",
"fields": {
"ngram": {
"type": "string",
"analyzer": "ngram_analyzer"
},
"spanish": {
"type": "string",
"analyzer": "spanish"
},
"english": {
"type": "string",
"analyzer": "english"
}
}
}
}
}
}

这样做的问题是我已经将每个字段及其分析器显式地写入搜索查询。
并且它将不允许使用“_all”进行搜索并使用多个分析器。

有没有一种方法可以使“_all”查询使用多个分析器?
诸如“_all.ngram”,“_ all.spanish”之类且不使用copy_做重复数据的东西?

是否可以将ngram分析器与西类牙语(或任何其他外语)组合并制作单个自定义分析器?
我已经测试了以下设置,但这些设置无效:
    PUT /ngrams_index
{
"settings": {
"number_of_shards": 1,
"analysis": {
"tokenizer": {
"ngram_tokenizer": {
"type": "nGram",
"min_gram": 3,
"max_gram": 3
}
},
"filter": {
"ngram_filter": {
"type": "nGram",
"min_gram": 3,
"max_gram": 3
},

"spanish_stop": {
"type": "stop",
"stopwords": "_spanish_"
},
"spanish_keywords": {
"type": "keyword_marker",
"keywords": ["ejemplo"]
},
"spanish_stemmer": {
"type": "stemmer",
"language": "light_spanish"
}


},
"analyzer": {
"ngram_analyzer": {
"type": "custom",
"tokenizer": "ngram_tokenizer",
"filter": [
"lowercase",
"spanish_stop",
"spanish_keywords",
"spanish_stemmer"
]
}
}
}
},
"mappings": {
"my_entity": {
"_all": {
"enabled": true,
"analyzer": "ngram_analyzer"
},

"properties": {
"my_field": {
"type": "text",
"fields": {
"analyzer1": {
"type": "string",
"analyzer": "ngram_analyzer"
},
"analyzer2": {
"type": "string",
"analyzer": "spanish"
},
"analyzer3": {
"type": "string",
"analyzer": "english"
}
}
}
}
}
}
}



GET /ngrams_index/_analyze
{
"field": "_all",
"text": "Hola, me llamo Juan."
}

返回值:仅ngram结果,没有西类牙语分析

哪里
    GET /ngrams_index/_analyze
{
"field": "my_field.analyzer2",
"text": "Hola, me llamo Juan."
}

正确分析搜索字符串。

是否可以构建结合西类牙语和ngram的自定义分析器?

最佳答案

有一种创建自定义ngram +语言分析器的方法:

PUT /ngrams_index
{
"settings": {
"number_of_shards": 1,
"analysis": {
"filter": {
"ngram_filter": {
"type": "nGram",
"min_gram": 3,
"max_gram": 3
},
"spanish_stop": {
"type": "stop",
"stopwords": "_spanish_"
},
"spanish_keywords": {
"type": "keyword_marker",
"keywords": [
"ejemplo"
]
},
"spanish_stemmer": {
"type": "stemmer",
"language": "light_spanish"
}
},
"analyzer": {
"ngram_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"spanish_stop",
"spanish_keywords",
"spanish_stemmer",
"ngram_filter"
]
}
}
}
},
"mappings": {
"my_entity": {
"_all": {
"enabled": true,
"analyzer": "ngram_analyzer"
},

"properties": {
"my_field": {
"type": "text",
"analyzer": "ngram_analyzer"
}
}
}
}
}


GET /ngrams_index/_analyze
{
"field": "my_field",
"text": "Hola, me llamo Juan."
}

关于elasticsearch - Elasticsearch :对同一数据运行多个分析器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47495490/

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