【问题标题】:Spring Data Elasticsearch Problem with IP_Range Data type具有 IP_Range 数据类型的 Spring Data Elasticsearch 问题
【发布时间】:2019-12-05 09:06:41
【问题描述】:

我使用 Spring Boot 2.0.1.RELEASE/Spring Data Elasticsearch 3.0.6。 我用@Document 注释注释了我的域类,并且我有一个如下字段:

@Field(store = true, type = FieldType.?)
private String ipRange;

如您所见,我需要将字段类型设置为 IP_Range(存在于弹性搜索引擎数据类型中) 但在 FieldType 枚举中不存在。

我想通过 ElasticsearchTemplate.createIndex(doc) 方法创建这个文档索引。但没有任何 FieldType 枚举支持 ip_range 数据类型。

【问题讨论】:

    标签: spring-boot spring-data spring-data-elasticsearch elasticsearch-6 custom-data-type


    【解决方案1】:

    Spring Data Elasticsearch 当前(3.2.0.M2)不支持这个。我看到你已经打开了一个问题,谢谢。这里的答案只是为了完整性和其他有同样问题的用户

    【讨论】:

      【解决方案2】:

      感谢@P.J.Meisch 的回复,我使用@Mapping 注解直接通过json 格式指定我的映射。 Spring data 已经支持基于这个配置创建索引。但我也在等待Range Data Structure Support 重构我的代码。

      我的文档:

      @Document(createIndex = true, indexName = "mydomain", type = "doc-rule"
              , refreshInterval = BaseDocument.REFRESH_INTERVAL, replicas = BaseDocument.REPLICA_COUNT, shards = BaseDocument.SHARD_COUNT)
      @Mapping(mappingPath = "/elasticsearch/mappings/mydomain-mapping.json")
      public class MyDomainDoc {
      
      @Field(store = true, type = FieldType.text)
      private List<String> ipRange;
      
      ... other fields
      
      }
      

      还有我的 mydomain-mapping.json 文件:

      {
        "properties": {
          ...,
          "ipRange": {
            "type": "ip_range",
            ...
          },
          ...
        }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-01-12
        • 2020-11-06
        • 2016-05-12
        • 1970-01-01
        • 2015-06-10
        • 2015-07-20
        • 2019-03-26
        • 1970-01-01
        相关资源
        最近更新 更多