[英]Can ElasticSearch _suggest query return multiple fields?
I have the following mapping for an index in which I'm doing a suggest/autocomplete lookup and response. 我在执行建议/自动完成查找和响应的索引中具有以下映射。
"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"
}
}
}
}
}
}
This is the endpoint and data for the request: site.dev:9200/listingsuggest/_suggest 这是请求的端点和数据:site.dev:9200/listingsuggest/_suggest
{
"result": {
"text": "Minn",
"completion": {
"field": "address.city"
}
}
}
So this works for finding documents that match cities starting with Minn. The issue I'm having is I also want to return the stateOrProvince field value of each document matching "Minn". 因此,这适用于查找与以Minn开头的城市匹配的文档,我遇到的问题是我还想返回与“ Minn”匹配的每个文档的stateOrProvince字段值。 For example my result set comes back with the following matched words:
例如,我的结果集返回了以下匹配的单词:
Minneapolis
Minnetonka
What I need it to do is return this: 我需要它做的是返回此:
Minneapolis, MN
Minnetonka, MN
The full response currently: 当前的完整回复:
{
_shards: {
total: 1
successful: 1
failed: 0
}
result: [{
text: Minn
offset: 0
length: 4
options: [{
text: Minnetonka
score: 1
} {
text: Minneapolis
score: 1
}]
}]
}
Desired full response if possible: 可能的话,请提供完整的答复:
{
_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
}]
}]
}
Is this, or some variation of that response, possible? 这是可能的,还是该响应的某种变化?
Yes it is possible! 对的,这是可能的! Try this:
尝试这个:
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"
}
}
}
}
}
}
}
You don't need address.stateOrProvince
. 您不需要
address.stateOrProvince
。
Post some data: 发布一些数据:
POST /listingsuggest/listing
{
"listingTitle" : "title1",
"address" : {
"city" : {
"input" : ["Minneapolis"],
"output" : "Minneapolis, MN"
}
}
}
POST /listingsuggest/listing
{
"listingTitle" : "title2",
"address" : {
"city" : {
"input": ["Minnetonka"],
"output" : "Minnetonka, MN"
}
}
}
And use this query: 并使用以下查询:
POST /listingsuggest/_suggest
{
"listing" : {
"text" : "Minn",
"completion" : {
"field" : "address.city"
}
}
}
It returns: 它返回:
"listing": [
{
"options": [
{
"text": "Minneapolis, MN",
"score": 1
},
{
"text": "Minnetonka, MN",
"score": 1
}
]
}
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.