【问题标题】:Is it possible to map Completion field with Context Suggester in spring-data-elasticsearch?是否可以在 spring-data-elasticsearch 中使用 Context Suggester 映射 Completion 字段?
【发布时间】:2019-06-10 12:57:19
【问题描述】:

我想在 Entity 中映射字段,例如 @CompletionField,但使用上下文,因为现在 Completion 包括 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"
        }

【问题讨论】:

  • 欢迎来到stackoverflow。你能提供更多细节吗?你都尝试了些什么?请阅读stackoverflow.com/help/how-to-ask
  • @zohar.kom 我的问题的新描述

标签: java spring-data spring-data-elasticsearch


【解决方案1】:

它已经被支持,你可以在这里找到例子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"
    }
  ]
}

【讨论】:

    猜你喜欢
    • 2017-05-18
    • 1970-01-01
    • 1970-01-01
    • 2015-07-08
    • 1970-01-01
    • 2020-11-18
    • 1970-01-01
    • 2022-06-15
    • 2015-10-19
    相关资源
    最近更新 更多