首页 > 解决方案 > 使用用于 rest-high-level-client 的 java 代码将完成建议添加到索引

问题描述

我的用例是,我的索引中需要有 4 个字段可以通过完成建议进行搜索,但是我的一些字段在插入时可以为空或 null,我在创建索引时尝试使用以下代码,但这会引发错误,因为其中两个插入时我的字段为空

    "CustomerName": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword"
                  }
                },
                "copy_to": [
                  "Suggestions.CustomerName"
                ]
              },
"FullAddress": {
                "type": "keyword",
                "copy_to": [
                  "Suggestions.FullAddress"
                ]
              },
"Contact": {
                "type": "keyword",
                "copy_to": [
                  "Suggestions.Contact"
                ]
              },
"CustomerId": {
                "type": "keyword",
                "copy_to": [
                  "Suggestions.CustomerId"
                ]
              }

如何使用 java 代码在弹性搜索中添加完成建议?我正在使用以下 Maven 依赖项:

<dependency>
    <groupId>org.elasticsearch.client</groupId>
    <artifactId>elasticsearch-rest-high-level-client</artifactId>
    <version>6.2.3</version>
</dependency>

标签: javaelasticsearch

解决方案


推荐阅读