[英]How to add custom name in elastic search using JEST client?
How to add custom name to elastic search using JEST client?如何使用 JEST 客户端向弹性搜索添加自定义名称?
For Example Using Spring data You can use custom name.例如使用 Spring 数据您可以使用自定义名称。 Spring Data ES use Jackson. Spring Data ES 使用 Jackson。 So, you can use @JsonProperty("your_custom_name")
to enable custom name in ES Mapping因此,您可以使用@JsonProperty("your_custom_name")
在 ES Mapping 中启用自定义名称
With jest client for elasticsearch, you need not specify any annotations for the field names.使用elasticsearch 的jest 客户端,您无需为字段名称指定任何注释。 The variable name itself is used by jest client to write data into elasticsearch. jest 客户端使用变量名称本身将数据写入 elasticsearch。 For example :例如:
class Article {
@JestId
private String documentId;
private String author;
private int pages;
}
Writing the above class will generate the documents with field names as documentId, author and pages.编写上述类将生成字段名称为 documentId、author 和 pages 的文档。
{
"documentId" : "doc_01",
"author" : "John Doe",
"pages" : 3
}
Jest client is using Gson for serialisation. Jest 客户端使用Gson进行序列化。 So, you can use the @SerializedName annotation for custom name.因此,您可以使用 @SerializedName 注释作为自定义名称。 Eg.例如。
class Article {
@JestId
private String documentId;
@SerializedName("author_name")
private String authorName;
@SerializedName("page_s")
private int pages;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.