我有一个Domain Class of Books 我将它用于hibernate和elasticsearch。
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.format.annotation.DateTimeFormat.ISO;
import com.fasterxml.jackson.annotation.JsonIgnore;
@Entity
@Table(name="books")
@Document(indexName="booksearchserver",type="book")
public class Book {
@org.springframework.data.annotation.Id
@Id
@Column(name="bookIsbn")
@Field(type = FieldType.Integer, store = true)
private long bookIsbn;
@Column(name="bookTitle")
@Field(type = FieldType.String, store = true)
private String bookTitle;
@Column(name="authorId")
@Field(type = FieldType.Integer, store = true)
private int bookAuthorId;
@Column(name="bookLanguage")
@Field(type = FieldType.String, store = true)
private String bookLanguage;
@Column(name="bookPublisherId")
@Field(type = FieldType.Integer, store = true)
private short bookPublisherId;
@Column(name="bookReleaseDate")
@DateTimeFormat(iso=ISO.DATE_TIME)
@Field(type = FieldType.Date, store = true, format=DateFormat.date)
private Date bookReleaseDate;
@JsonIgnore
@Column(name="bookNoOfChapters")
private short bookNoOfChapters;
@JsonIgnore
@Column(name="bookNoOfPages")
private short bookNoOfPages;
@JsonIgnore
@Column(name="bookNoOfWords")
private int bookWordCount;
@JsonIgnore
@Column(name="bookPrecededByIsbn" )
private long bookPrecededBy;
@JsonIgnore
@Column(name="bookFollowedByIsbn")
private long bookFollowedBy;
@Column(name="bookDescription")
@Field(type = FieldType.String, store = true )
private String bookDescription;
@JsonIgnore
@Column(name="bookCoverImage")
private String bookCover;
我有一个存储库类
package co.in.searchServer.repository;
org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import co.in.searchServer.model.Book;
public interface ESDao extends ElasticsearchRepository<Book,Long> {
Iterable<Book> search(QueryBuilder arg0);
Book findBybookIsbn(long isbn);
<S extends Book> S index(S arg0);
}
做一个
GET booksearchserver/book/_mapping
{
"booksearchserver": {
"mappings": {
"book": {
"properties": {
"bookAuthorId": {
"type": "integer",
"store": true
},
"bookDescription": {
"type": "string",
"store": true
},
"bookIsbn": {
"type": "string",
"index": "not_analyzed"
},
"bookLanguage": {
"type": "string",
"store": true
},
"bookPublisherId": {
"type": "integer",
"store": true
},
"bookReleaseDate": {
"type": "date",
"store": true,
"format": "date"
},
"bookTitle": {
"type": "string",
"store": true
}
}
}
}
}
}
我遇到以下问题:
我也尝试过使用elasticsearchTemplate类进行映射。
我认为Field Annotations不起作用。
请提供一些经验和解决方案