gpt4 book ai didi

elasticsearch - Elasticsearch嵌套映射似乎不起作用

转载 作者:行者123 更新时间:2023-12-02 23:31:03 24 4
gpt4 key购买 nike

鉴于以下文件,

{
"domain": "www.example.com",
"tag": [
{
"name": "IIS"
},
{
"name": "Microsoft ASP.NET"
}
]
}

当我启动 aspasp.net的查询时,我希望在结果集中看到 Microsoft ASP.NET文档。

因此,我需要一个小写的分析器并从单词定界符中删除 .字符,因此我尝试了以下映射,
curl -XPUT http://localhost:9200/tag-test -d '{
"settings": {
"analysis": {
"filter": {
"domain_filter": {
"type": "word_delimiter",
"type_table": [". => ALPHANUM", ": => ALPHANUM"]
}
},
"analyzer": {
"domain_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": ["lowercase", "domain_filter"]
}
}
}
},
"mappings": {
"assets": {
"properties": {
"domain": {
"type": "string",
"analyzer": "domain_analyzer"
},
"tag": {
"type": "nested",
"properties": {
"name": {
"type": "string",
"analyzer": "domain_analyzer"
}
}
}
}
}
}
}'; echo

然后,我尝试了以下查询,所有查询均产生空结果
tag.name:asp
tag.name:asp.net
tag.name:*asp*

我正在使用querystring查询,
curl http://localhost:9200/tag-test/_search?q=tag.name:asp

有任何想法吗?

最佳答案

首先,query_string查询不支持嵌套查询和,除非在映射中使用include_in_parent: true(它将使父文档中的数组中的nested字段变平),否则query_string将永远无法使用。

其次,在您的分析器中,您将拥有asp.net作为在Elasticsearch中被索引的术语。这意味着query_string将与tag.name:asp.nettag.name:*asp*一起使用。我建议不要使用前导通配符

因此,最后您的测试应该是:

PUT /tag-test
{
"settings": {
"analysis": {
"filter": {
"domain_filter": {
"type": "word_delimiter",
"type_table": [
". => ALPHANUM",
": => ALPHANUM"
]
}
},
"analyzer": {
"domain_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase",
"domain_filter"
]
}
}
}
},
"mappings": {
"assets": {
"properties": {
"domain": {
"type": "string",
"analyzer": "domain_analyzer"
},
"tag": {
"type": "nested",
"include_in_parent": true,
"properties": {
"name": {
"type": "string",
"analyzer": "domain_analyzer"
}
}
}
}
}
}
}

注意 "include_in_parent": true的映射中的 tag
然后查询应为:
  • curl -XGET "http://localhost:9200/tag-test/_search?q=tag.name:asp*"
  • curl -XGET "http://localhost:9200/tag-test/_search?q=tag.name:asp.net"
  • 关于elasticsearch - Elasticsearch嵌套映射似乎不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36419263/

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