gpt4 book ai didi

full-text-search - ElasticSearch中的多语言查询

转载 作者:行者123 更新时间:2023-12-02 22:34:07 25 4
gpt4 key购买 nike

假设我们在ElasticSearch中具有以下映射。

{
"content": {
"properties": {
"id": {
"type": "string",
"index": "not_analyzed",
"store": "yes"
},
"locale_container": {
"type": "object",
"properties": {
"english": {
"type": "object",
"properties": {
"title": {
"type": "string",
"index_analyzer": "english",
"search_analyzer": "english",
"index": "analyzed",
"term_vector": "with_positions_offsets",
"store": "yes"
},
"text": {
"type": "string",
"index_analyzer": "english",
"search_analyzer": "english",
"index": "analyzed",
"term_vector": "with_positions_offsets",
"store": "yes"
}
}
},
"german": {
"type": "object",
"properties": {
"title": {
"type": "string",
"index_analyzer": "german",
"search_analyzer": "german",
"index": "analyzed",
"term_vector": "with_positions_offsets",
"store": "yes"
},
"text": {
"type": "string",
"index_analyzer": "german",
"search_analyzer": "german",
"index": "analyzed",
"term_vector": "with_positions_offsets",
"store": "yes"
}
}
},
"russian": {
"type": "object",
"properties": {
"title": {
"type": "string",
"index_analyzer": "russian",
"search_analyzer": "russian",
"index": "analyzed",
"term_vector": "with_positions_offsets",
"store": "yes"
},
"text": {
"type": "string",
"index_analyzer": "russian",
"search_analyzer": "russian",
"index": "analyzed",
"term_vector": "with_positions_offsets",
"store": "yes"
}
}
},
"italian": {
"type": "object",
"properties": {
"title": {
"type": "string",
"index_analyzer": "italian",
"search_analyzer": "italian",
"index": "analyzed",
"term_vector": "with_positions_offsets",
"store": "yes"
},
"text": {
"type": "string",
"index_analyzer": "italian",
"search_analyzer": "italian",
"index": "analyzed",
"term_vector": "with_positions_offsets",
"store": "yes"
}
}
}
}
}
}
}
}

当特定用户查询索引时,我们可以从她的设置中获取其文化,即我们知道要使用哪个分析器。我们该如何制定一个查询,以她自己的语言(比如德语)仅搜索“标题”和“文本”字段,并使用德语分析器对搜索查询进行标记?

最佳答案

我简化了该示例,将standard分析器用于“英语”,将simple(不停止)用于“法语”。对于这样的文档:

{
id: "abc",
locale_container: {
english: {
title: "abc to ABC",
text: ""
},
french: {
title: "def to DEF",
text: ""
}
}
}

以下查询可以解决问题:
  • locale_container.english.title:abc->返回文档
  • locale_container.french.title:def->也返回文档
  • locale_container.english.title:to->不返回任何内容,因为“to”是停用词
  • locale_container.french.title:to->返回文档
  • 关于full-text-search - ElasticSearch中的多语言查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7406692/

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