spring-data-elasticsearch 查询时 elasticsearch 的索引带有下划线时怎么处理

a13891630987 2019-08-01 04:45:13
比如这个的pres_rq字段.

实体类使用了@JsonProperty进行标记,测试可以获取到值,也能将值传入es,但是用作查询条件时,如果用findAllByPresRq 无法查询
如果用findAllByPres_Rq 会报错

...全文
1480 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
阿葉丶 2020-04-07
  • 打赏
  • 举报
回复
引用 8 楼 喝酒的猫 的回复:
[quote=引用 7 楼 阿葉丶 的回复:] [quote=引用 6 楼 喝酒的猫 的回复:] 这个问题也困扰了我很久,网上关于这方面的确实资料很少,不过还是解决了,官方文档还是靠谱。 主要原因是数据模型的配置,使用spring-data-elasticsearch时候我们一般都是默认配置,问题就出在这里,默认配置中的数据模型使用的是Jackson Object Mapping,在使用这种数据模型时候,@Field是不起作用的。 这时候就用到了另一种数据模型映射(Meta Model Object Mapping),这种映射支持字段的详细配置,具体配置参看官网链接 ,这里贴出@field的部分配置。 @Field: Applied at the field level and defines properties of the field, most of the attributes map to the respective Elasticsearch Mapping definitions: name: The name of the field as it will be represented in the Elasticsearch document, if not set, the Java field name is used. type: the field type, can be one of Text, Integer, Long, Date, Float, Double, Boolean, Object, Auto, Nested, Ip, Attachment, Keyword. format and pattern custom definitions for the Date type. store: Flag wether the original field value should be store in Elasticsearch, default value is false. analyzer, searchAnalyzer, normalizer for specifying custom custom analyzers and normalizer. copy_to: the target field to copy multiple document fields to. 最后总结解决方案: 1. 添加配置文件 @Configuration public class Config extends AbstractElasticsearchConfiguration { @Override public RestHighLevelClient elasticsearchClient() { return RestClients.create(ClientConfiguration.create("localhost:9200")).rest() } @Bean @Override public EntityMapper entityMapper() { ElasticsearchEntityMapper entityMapper = new ElasticsearchEntityMapper( elasticsearchMappingContext(), new DefaultConversionService() ); entityMapper.setConversions(elasticsearchCustomConversions()); return entityMapper; } } 2. 在字段上使用注解 @Field(type = FieldType.Text, name="src_ip") private String srcIp;
name属性是不是只有高版本才有[/quote] 我使用这个API一般都是使用最新版,这个没有找到像ES那样详细到各个版本都分类好的文档[/quote] 额。我spring boot版本2.1.9 我看官网推荐就用了6.2.2.。我最终是通过@JsonProperty("class_id")这个注解去解决的这个问题。。
喝酒的猫 2020-04-07
  • 打赏
  • 举报
回复
引用 7 楼 阿葉丶 的回复:
[quote=引用 6 楼 喝酒的猫 的回复:] 这个问题也困扰了我很久,网上关于这方面的确实资料很少,不过还是解决了,官方文档还是靠谱。 主要原因是数据模型的配置,使用spring-data-elasticsearch时候我们一般都是默认配置,问题就出在这里,默认配置中的数据模型使用的是Jackson Object Mapping,在使用这种数据模型时候,@Field是不起作用的。 这时候就用到了另一种数据模型映射(Meta Model Object Mapping),这种映射支持字段的详细配置,具体配置参看官网链接 ,这里贴出@field的部分配置。 @Field: Applied at the field level and defines properties of the field, most of the attributes map to the respective Elasticsearch Mapping definitions: name: The name of the field as it will be represented in the Elasticsearch document, if not set, the Java field name is used. type: the field type, can be one of Text, Integer, Long, Date, Float, Double, Boolean, Object, Auto, Nested, Ip, Attachment, Keyword. format and pattern custom definitions for the Date type. store: Flag wether the original field value should be store in Elasticsearch, default value is false. analyzer, searchAnalyzer, normalizer for specifying custom custom analyzers and normalizer. copy_to: the target field to copy multiple document fields to. 最后总结解决方案: 1. 添加配置文件 @Configuration public class Config extends AbstractElasticsearchConfiguration { @Override public RestHighLevelClient elasticsearchClient() { return RestClients.create(ClientConfiguration.create("localhost:9200")).rest() } @Bean @Override public EntityMapper entityMapper() { ElasticsearchEntityMapper entityMapper = new ElasticsearchEntityMapper( elasticsearchMappingContext(), new DefaultConversionService() ); entityMapper.setConversions(elasticsearchCustomConversions()); return entityMapper; } } 2. 在字段上使用注解 @Field(type = FieldType.Text, name="src_ip") private String srcIp;
name属性是不是只有高版本才有[/quote] 我使用这个API一般都是使用最新版,这个没有找到像ES那样详细到各个版本都分类好的文档
阿葉丶 2020-04-06
  • 打赏
  • 举报
回复
引用 6 楼 喝酒的猫 的回复:
这个问题也困扰了我很久,网上关于这方面的确实资料很少,不过还是解决了,官方文档还是靠谱。 主要原因是数据模型的配置,使用spring-data-elasticsearch时候我们一般都是默认配置,问题就出在这里,默认配置中的数据模型使用的是Jackson Object Mapping,在使用这种数据模型时候,@Field是不起作用的。 这时候就用到了另一种数据模型映射(Meta Model Object Mapping),这种映射支持字段的详细配置,具体配置参看官网链接 ,这里贴出@field的部分配置。 @Field: Applied at the field level and defines properties of the field, most of the attributes map to the respective Elasticsearch Mapping definitions: name: The name of the field as it will be represented in the Elasticsearch document, if not set, the Java field name is used. type: the field type, can be one of Text, Integer, Long, Date, Float, Double, Boolean, Object, Auto, Nested, Ip, Attachment, Keyword. format and pattern custom definitions for the Date type. store: Flag wether the original field value should be store in Elasticsearch, default value is false. analyzer, searchAnalyzer, normalizer for specifying custom custom analyzers and normalizer. copy_to: the target field to copy multiple document fields to. 最后总结解决方案: 1. 添加配置文件 @Configuration public class Config extends AbstractElasticsearchConfiguration { @Override public RestHighLevelClient elasticsearchClient() { return RestClients.create(ClientConfiguration.create("localhost:9200")).rest() } @Bean @Override public EntityMapper entityMapper() { ElasticsearchEntityMapper entityMapper = new ElasticsearchEntityMapper( elasticsearchMappingContext(), new DefaultConversionService() ); entityMapper.setConversions(elasticsearchCustomConversions()); return entityMapper; } } 2. 在字段上使用注解 @Field(type = FieldType.Text, name="src_ip") private String srcIp;
name属性是不是只有高版本才有
喝酒的猫 2020-03-10
  • 打赏
  • 举报
回复
这个问题也困扰了我很久,网上关于这方面的确实资料很少,不过还是解决了,官方文档还是靠谱。 主要原因是数据模型的配置,使用spring-data-elasticsearch时候我们一般都是默认配置,问题就出在这里,默认配置中的数据模型使用的是Jackson Object Mapping,在使用这种数据模型时候,@Field是不起作用的。 这时候就用到了另一种数据模型映射(Meta Model Object Mapping),这种映射支持字段的详细配置,具体配置参看官网链接 ,这里贴出@field的部分配置。 @Field: Applied at the field level and defines properties of the field, most of the attributes map to the respective Elasticsearch Mapping definitions: name: The name of the field as it will be represented in the Elasticsearch document, if not set, the Java field name is used. type: the field type, can be one of Text, Integer, Long, Date, Float, Double, Boolean, Object, Auto, Nested, Ip, Attachment, Keyword. format and pattern custom definitions for the Date type. store: Flag wether the original field value should be store in Elasticsearch, default value is false. analyzer, searchAnalyzer, normalizer for specifying custom custom analyzers and normalizer. copy_to: the target field to copy multiple document fields to. 最后总结解决方案: 1. 添加配置文件 @Configuration public class Config extends AbstractElasticsearchConfiguration { @Override public RestHighLevelClient elasticsearchClient() { return RestClients.create(ClientConfiguration.create("localhost:9200")).rest() } @Bean @Override public EntityMapper entityMapper() { ElasticsearchEntityMapper entityMapper = new ElasticsearchEntityMapper( elasticsearchMappingContext(), new DefaultConversionService() ); entityMapper.setConversions(elasticsearchCustomConversions()); return entityMapper; } } 2. 在字段上使用注解 @Field(type = FieldType.Text, name="src_ip") private String srcIp;

51,411

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧