Spring 数据 Elasticsearch 问题 IP_Range 数据类型

Spring Data Elasticsearch Problem with IP_Range Data type

我使用 Spring boot 2.0.1.RELEASE/ Spring Data Elasticsearch 3.0.6。 我用 @Document 注释注释我的域 class 并且我有一个如下所示的字段:

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

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

我想通过 ElasticsearchTemplate.createIndex(doc) 方法创建此文档索引。但是任何 FieldType 枚举的 none 都支持 ip_range 数据类型。

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

感谢@P.J.Meisch的回复,我使用@Mapping注解直接通过json格式指定我的映射。 Spring 数据已经支持基于此配置创建索引。但我也在等待 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",
      ...
    },
    ...
  }
}