弹性弹性搜索自定义字段名称 [英] Spring Elastic Search Custom Field names

查看:114
本文介绍了弹性弹性搜索自定义字段名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有新的弹性搜索,我正在尝试使用Spring-data-elasticsearch实现它。我有一个名称如交通,我们的弹性搜索文件中的Telephone_Number。



当我尝试将我的@Domain对象字段映射到这些对象字段时,我没有得到任何数据,因为我不能成功地映射这些字段。



尝试使用@Field,令人失望,因为它没有name属性来映射自定义字段名称。 >

尝试了GETTER函数的不同变体,没有一个似乎映射到这些字段。



我开始想知道是否有一些我在这里错过的东西
域对象字段的外观如何映射到称为运输的文件?



任何帮助赞赏

解决方案

您可以使用自定义名称。 Spring Data ES使用Jackson。因此,您可以使用 @JsonProperty(your_custom_name)在ES映射



中启用自定义名称:

  @Document(indexName =your_index_name,type =your_type_name)
public class YourEntity {
....
@JsonProperty(my_transportation)
@Field(type = FieldType.String,searchAnalyzer =standard,indexAnalyzer =standard,store = true)//例如
private String myTransportation;
....
}

注意:我很抱歉,我的英文不好..:D


I am new to Elastic Search and I am trying to implement it using Spring-data-elasticsearch.

I have fields with names such as "Transportation", "Telephone_Number" in our elastic search documents.

When I try to map my @Domain object fields with those, I don't get any data for those as I couldn't successfully map those fields.

Tried to use @Field, was disappointed as it didn't have 'name' property in it to map with custom field name.

Tried different variations of a GETTER function, none of those seem to be mapping to those fields.

I started wondering if there's something I'm missing here. How does a domain object field look like which should map to a filed called something like "Transportation" ?

Any help appreciated

解决方案

You can use custom name. Spring Data ES use Jackson. So, you can use @JsonProperty("your_custom_name") to enable custom name in ES Mapping

for example:

@Document(indexName = "your_index_name", type = "your_type_name")
public class YourEntity {
   ....
   @JsonProperty("my_transportation")
   @Field(type = FieldType.String, searchAnalyzer = "standard", indexAnalyzer = "standard", store = true) // just for example
   private String myTransportation;
   ....
}

Note: I'm sorry anyway, my english is bad.. :D

这篇关于弹性弹性搜索自定义字段名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆