gpt4 book ai didi

elasticsearch - elasticsearch-构建查询时如何引用多字段

转载 作者:行者123 更新时间:2023-12-03 02:10:19 26 4
gpt4 key购买 nike

我无法使用导航符号访问多个字段

我的映射:

{
"mappings":{
"document":{
"properties":{
"tags":{
"type":"object",
"properties":{
"title":{
"fields":{
"partial":{
"search_analyzer":"main",
"index_analyzer":"partial",
"type":"string"
},
"title":{
"type":"string",
"analyzer":"main"
},
"title2":{
"type":"string",
"analyzer":"main"
}
},
"type":"multi_field"
}
}
}
}
}
},

"settings":{
"analysis":{
"filter":{
"name_ngrams":{
"side":"front",
"max_gram":50,
"min_gram":2,
"type":"edgeNGram"
},
"name_ngrams_back":{
"side":"back",
"max_gram":50,
"min_gram":2,
"type":"edgeNGram"
},
"name_middle_ngrams":{
"type":"nGram",
"max_gram":50,
"min_gram":2
}
},

"analyzer":{
"main":{
"filter": ["standard", "lowercase", "asciifolding"],
"type": "custom",
"tokenizer": "standard"
},
"partial":{
"filter":["standard","lowercase","asciifolding","name_ngrams"],
"type": "custom",
"tokenizer": "standard"
}
}
}
}

}

测试数据:
curl -XPUT localhost:9200/testindex/document/1 -d '{"title": "Fight for your life"}'
curl -XPUT localhost:9200/testindex/document/2 -d '{"title": "Fighting for your life"}'
curl -XPUT localhost:9200/testindex/document/3 -d '{"title": "Will you just start the fight"}'

搜索:
 curl -XGET 'localhost:9200/testindex/document/_search?q=title:life&pretty=1'                   // Ok
curl -XGET 'localhost:9200/testindex/document/_search?q=document.title:life&pretty=1' // Ok

// Return 0 hits. I expect this to return same result as the above queries.
curl -XGET 'localhost:9200/testindex/document/_search?q=title.title2:life&pretty=1'
curl -XGET 'localhost:9200/testindex/document/_search? q=document.title.title2:life&pretty=1'

构建查询时如何引用多个字段?

最佳答案

您已经为tags.title字段定义了多字段映射,但是您正在索引和搜索title字段。试试这个测试数据:

curl -XPUT localhost:9200/testindex/document/1 -d '{"tags":{"title": "Fight for your life"}}'
curl -XPUT localhost:9200/testindex/document/2 -d '{"tags":{"title": "Fighting for your life"}}'
curl -XPUT localhost:9200/testindex/document/3 -d '{"tags":{"title": "Will you just start the fight"}}'

以下搜索:
curl -XGET 'localhost:9200/testindex/document/_search?q=title:life&pretty=1'
curl -XGET 'localhost:9200/testindex/document/_search?q=tags.title:life&pretty=1'
curl -XGET 'localhost:9200/testindex/document/_search?q=document.tags.title:life&pretty=1'

curl -XGET 'localhost:9200/testindex/document/_search?q=title2:life&pretty=1'
curl -XGET 'localhost:9200/testindex/document/_search?q=tags.title.title2:life&pretty=1'
curl -XGET 'localhost:9200/testindex/document/_search?q=document.tags.title.title2:life&pretty=1'

关于elasticsearch - elasticsearch-构建查询时如何引用多字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13215435/

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