gpt4 book ai didi

elasticsearch - ElasticSearch _suggest查询可以返回多个字段吗?

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

我在执行建议/自动完成查找和响应的索引中具有以下映射。

"mappings": {
"listing": {
"_source": {
"enabled": false
},
"dynamic": false,
"properties": {
"_all": {
"enabled": false
},
"listingTitle": {
"type": "completion",
"index_analyzer": "str_index_analyzer",
"search_analyzer": "str_search_analyzer"
},
"address": {
"dynamic": false,
"properties": {
"city": {
"type": "completion",
"index_analyzer": "str_index_analyzer",
"search_analyzer": "str_search_analyzer"
},
"stateOrProvince": {
"type": "completion",
"index_analyzer": "str_index_analyzer",
"search_analyzer": "str_search_analyzer"
}
}
}
}
}
}

这是请求的端点和数据:site.dev:9200/listingsuggest/_suggest
{
"result": {
"text": "Minn",
"completion": {
"field": "address.city"
}
}
}

因此,这适用于查找与以Minn开头的城市匹配的文档。我遇到的问题是我还想返回与“Minn”匹配的每个文档的stateOrProvince字段值。例如,我的结果集返回了以下匹配的单词:
Minneapolis
Minnetonka

我需要它做的是返回此:
Minneapolis, MN
Minnetonka, MN

当前的完整回复:
{
_shards: {
total: 1
successful: 1
failed: 0
}
result: [{
text: Minn
offset: 0
length: 4
options: [{
text: Minnetonka
score: 1
} {
text: Minneapolis
score: 1
}]
}]
}

可能的话,请提供完整的答复:
{
_shards: {
total: 1
successful: 1
failed: 0
}
result: [{
text: Minn
offset: 0
length: 4
options: [{
text: Minnetonka, MN
score: 1
} {
text: Minneapolis, MN
score: 1
}]
}]
}

这是可能的,还是该响应的某种变化?

最佳答案

是的,有可能!试试这个:

PUT /listingsuggest
{
"mappings": {
"listing": {
"_source": {
"enabled": false
},
"dynamic": false,
"properties": {
"_all": {
"enabled": false
},
"listingTitle": {
"type": "completion",
"index_analyzer": "standard",
"search_analyzer": "standard"
},
"address": {
"dynamic": false,
"properties": {
"city": {
"type": "completion",
"index_analyzer": "standard",
"search_analyzer": "standard"
}
}
}
}
}
}
}

您不需要 address.stateOrProvince

发布一些数据:
POST /listingsuggest/listing
{
"listingTitle" : "title1",
"address" : {
"city" : {
"input" : ["Minneapolis"],
"output" : "Minneapolis, MN"
}
}
}

POST /listingsuggest/listing
{
"listingTitle" : "title2",
"address" : {
"city" : {
"input": ["Minnetonka"],
"output" : "Minnetonka, MN"
}
}
}

并使用以下查询:
POST /listingsuggest/_suggest
{
"listing" : {
"text" : "Minn",
"completion" : {
"field" : "address.city"
}
}
}

它返回:
   "listing": [
{
"options": [
{
"text": "Minneapolis, MN",
"score": 1
},
{
"text": "Minnetonka, MN",
"score": 1
}
]
}
]

关于elasticsearch - ElasticSearch _suggest查询可以返回多个字段吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25165604/

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