java - 是否可以在 spring-data-elasticsearch 中使用 Context Suggester 映射 Completion 字段?
问题描述
我想在像@CompletionField 这样的实体中映射字段,但是使用上下文,因为现在完成包括String []和int权重字段。我想过滤索引中的完成。
@Document(indexName = "compl_index")
public class ComplIndex {
@CompletionField
private Completion suggestions;
}
当我编写这个类时,我有一个简单的字符串数组和权重完成,但我想像这样映射实体,并使用上下文。我尝试解决这个问题 - 使用字段类型、上下文等编写一个新实体并使用映射进行注释,CompletionFieldMapper 抛出异常“字段不支持上下文字段:...
"name": {
"type": "completion",
"contexts": [
{
"name": "year",
"type": "category",
"path": "year"
}
]
},
"year": {
"type": "text"
}
解决方案
它已经被支持,你可以在这里找到示例DATAES-536。对于较低版本,您需要编写自定义完成模型并使用字段@Mapping 而不是@CompletionField。
public class CustomCompletion {
private String[] input;
private Map<String, List<String>> contexts;
private Integer weight;
private CustomCompletion() {
// required by mapper to instantiate object
}
public CustomCompletion(String[] input) {
this.input = input;
}
// Setter getter
}
@Document(indexName = "compl_index")
public class ComplIndex {
@Mapping(mappingPath = "/mapping/compl-index-suggestions.json")
private CustomCompletion suggestions;
}
compl-index-suggestions.json
{
"type": "completion",
"contexts": [
{
"name": "year",
"type": "category"
}
]
}
推荐阅读
- java - 如何解析日期时间并将其与相应的时区相关联
- cygwin - u-boot在cygwin上交叉编译
- node.js - 为 Angular 8 中的单个文件创建自定义 404 错误
- c - 粉碎堆栈 - 找不到返回地址
- excel - 颜色排序后单元格的 RGB 值不更新
- java - 使用 Collections Google/gson 库更新 JSON 文件
- r - 在 R 中重采样面板数据结构
- bash - 循环一系列日期。d=$(date -I -d "$d + 1 day") 不工作
- javascript - 检测 selectionStart 处的单词是否为 URL
- sql - 子账户 sql