我想要映射@CompletionField之类的Entity中的字段,但是具有上下文,因为现在Completion包含String []和int weight字段。我想过滤索引中的完成。
@Document(indexName = "compl_index")
public class ComplIndex {
@CompletionField
private Completion suggestions;
}
当我编写此类时,我对字符串数组和权重有一个简单的完成,但是我想像这样映射实体并使用上下文。我尝试解决此问题-使用字段类型,上下文等编写新实体,并使用Mapping,CompletionFieldMapper抛出异常“字段不支持上下文字段:...
"name": {
"type": "completion",
"contexts": [
{
"name": "year",
"type": "category",
"path": "year"
}
]
},
"year": {
"type": "text"
}
答案 0 :(得分:0)
它已经受支持,您可以在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"
}
]
}