elasticsearch - ElasticSearch 7.6.3 Java HighLevel Rest Client:跨多个字段的自动建议 - 如何实现
问题描述
我们有一个包含以下字段的索引,并且需要通过在索引中的所有文本和关键字映射字段中搜索数据来向用户提供自动建议
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 1,
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 20
}
},
}
},
"mappings": {
"properties": {
"id": {
"type": "text"
},
"title": {
"type": "text"
},
"date": {
"type": "date",
"format": "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
},
"subject": {
"type": "text"
},
"title_suggest": {
"type": "completion",
"analyzer": "simple",
"preserve_separators": true,
"preserve_position_increments": true,
"max_input_length": 50
},
"subject_suggest": {
"type": "completion",
"analyzer": "simple",
"preserve_separators": true,
"preserve_position_increments": true,
"max_input_length": 50
}
"fieldOr": {
"type": "text"
},
"fieldsTa": {
"type": "text"
},
"notes": {
"type": "text"
},
"fileDocs": {
"type": "nested",
"properties": {
"fileName": {
"type": "text",
"analyzer": "autocomplete",
"search_analyzer": "standard"
},
"fileContent": {
"type": "text",
"analyzer": "autocomplete",
"search_analyzer": "standard"
},
"docType": {
"type": "keyword"
},
"opinionId": {
"type": "integer"
}
}
},
"fileMeta": {
"type": "nested",
"properties": {
"url": {
"type": "text"
},
"name": {
"type": "text"
}
}
}
}
}
}
我已经尝试过 Completion Suggest,但它适用于 1 个字段。我在索引中创建了 2 个带有 *-suggest 的字段,并尝试使用 completionSuggest 创建建议
SuggestBuilders.completionSuggestion("my_index_suggest").text(input);
但它只支持 1 个字段。我将 ES 7.6.3 与 Java HighLevel Rest Client 一起使用,它适用于 1 个字段。我需要做哪些改变来支持跨多个领域。这可以通过 JSON 搜索实现吗?如果是,那么我可以使用 Xcontentbuilder 创建一个 json 并执行自动建议?
解决方案
使用copy_to并将您所需的所有字段复制到一个字段并在其上执行您的建议。
copy_to 文档中的示例是,
PUT my_index
{
"mappings": {
"properties": {
"first_name": {
"type": "text",
"copy_to": "full_name"
},
"last_name": {
"type": "text",
"copy_to": "full_name"
},
"full_name": {
"type": "text"
}
}
}
}
推荐阅读
- php - 如何过滤 wordpress/php 中的类别?
- c++ - c ++ Sentinel循环,存储最小和最大数字
- javascript - 表格单元格在单击事件后意外更改大小
- php - 使用多个条件对数组值求和
- excel - 如何将我的 Outlook 电子邮件(在特定时间段内)复制到 Excel?
- excel-formula - 检查两个列表之间的新项目数量
- angular - 跨项目共享 ionic 4 / angular7 模块
- php - 小部件中的 yii2 ajax 验证错误,yii\web\Response
- mongodb - 使用错误索引的 MongoDB 查询
- c# - 为所有 WEB API 控制器指定 API 版本