Spring数据弹性搜索

时间:2018-09-20 01:46:06

标签: elasticsearch elastic-stack spring-data-elasticsearch amazon-elastic-beanstalk

我正在尝试根据属于嵌套类(即子类)的字段获取对象。但是,尽管我在进行存储库调用时传递了所有必需的参数,但是在控制台中以“ NullPointerException”的身份执行elasticsearchrepository查询时却出错了。

这是我的弹性搜索存储库查询,无法识别此查询对共享pojo结构的错误。

@Query("{\"bool\": {\"must\":[{\"match_all\":{}}],\"filter\":{\"terms\":[{\"metadata.tags\":\" ?0\"}]}}}")
Page<Episode> findByTags(String tags, Pageable pageable);

控制台错误

java.lang.NullPointerException: null
at org.elasticsearch.common.ParseField.match(ParseField.java:83) ~[elasticsearch-2.4.4.jar:2.4.4]
at org.elasticsearch.common.ParseFieldMatcher.match(ParseFieldMatcher.java:58) ~[elasticsearch-2.4.4.jar:2.4.4]
at org.elasticsearch.index.query.QueryParseContext.isDeprecatedSetting(QueryParseContext.java:385) ~[elasticsearch-2.4.4.jar:2.4.4]
at org.elasticsearch.index.query.TermsQueryParser.parse(TermsQueryParser.java:94) ~[elasticsearch-2.4.4.jar:2.4.4]
at org.elasticsearch.index.query.QueryParseContext.parseInnerQuery(QueryParseContext.java:250) ~[elasticsearch-2.4.4.jar:2.4.4]
at org.elasticsearch.index.query.QueryParseContext.parseInnerFilter(QueryParseContext.java:263) ~[elasticsearch-2.4.4.jar:2.4.4]
at org.elasticsearch.index.query.BoolQueryParser.parse(BoolQueryParser.java:91) ~[elasticsearch-2.4.4.jar:2.4.4]
at org.elasticsearch.index.query.QueryParseContext.parseInnerQuery(QueryParseContext.java:250) ~[elasticsearch-2.4.4.jar:2.4.4]
at org.elasticsearch.index.query.IndexQueryParserService.innerParse(IndexQueryParserService.java:324) ~[elasticsearch-2.4.4.jar:2.4.4]
at org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:224) ~[elasticsearch-2.4.4.jar:2.4.4]
at org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:219) ~[elasticsearch-2.4.4.jar:2.4.4]
at org.elasticsearch.search.query.QueryBinaryParseElement.parse(QueryBinaryParseElement.java:36) ~[elasticsearch-2.4.4.jar:2.4.4]
at org.elasticsearch.search.SearchService.parseSource(SearchService.java:856) ~[elasticsearch-2.4.4.jar:2.4.4]
at org.elasticsearch.search.SearchService.createContext(SearchService.java:667) ~[elasticsearch-2.4.4.jar:2.4.4]
at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:633) ~[elasticsearch-2.4.4.jar:2.4.4]
at org.elasticsearch.search.SearchService.executeFetchPhase(SearchService.java:472) ~[elasticsearch-2.4.4.jar:2.4.4]
at org.elasticsearch.search.action.SearchServiceTransportAction$SearchQueryFetchTransportHandler.messageReceived(SearchServiceTransportAction.java:392) ~[elasticsearch-2.4.4.jar:2.4.4]
at org.elasticsearch.search.action.SearchServiceTransportAction$SearchQueryFetchTransportHandler.messageReceived(SearchServiceTransportAction.java:389) ~[elasticsearch-2.4.4.jar:2.4.4]
at org.elasticsearch.transport.TransportRequestHandler.messageReceived(TransportRequestHandler.java:33) ~[elasticsearch-2.4.4.jar:2.4.4]
at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:77) ~[elasticsearch-2.4.4.jar:2.4.4]
at org.elasticsearch.transport.TransportService$4.doRun(TransportService.java:378) ~[elasticsearch-2.4.4.jar:2.4.4]
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) ~[elasticsearch-2.4.4.jar:2.4.4]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_181]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_181]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_181]

Pojo对象结构

@Entity
@JsonPropertyOrder({
"title",
"metadata",
"status",
"id",
"date"
})
@Document(indexName = "video", type = "episode", shards = 1)
public class Episode {

	@Id
	@GeneratedValue(generator = "uuid")
	@GenericGenerator(name = "uuid", strategy = "uuid2")
	@Column(name = "id", unique = true)
	@JsonProperty("id")
	private String id;
	
	@JsonProperty("title")
	private String title;
	
	@OneToOne(cascade = CascadeType.ALL)
	@JoinColumn(name = "metaId")
	@JsonProperty("metadata")
	@Field(type = FieldType.Nested, includeInParent = true)
	private Metadata metadata;
	
	@JsonProperty("status")
	private String status;
	
	@JsonProperty("date")
	private Date date;

	public Episode() {
		super();
	}

	public Episode(String title, Metadata metadata, String status, Date date) {
		super();
		this.title = title;
		this.metadata = metadata;
		this.status = status;
		this.date = date;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public Metadata getMetadata() {
		return metadata;
	}

	public void setMetadata(Metadata metadata) {
		this.metadata = metadata;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

}

@Entity
@JsonPropertyOrder({
"region",
"long_synopsis",
"meta_desc",
"tags"
})
public class Metadata {

	@Id
	@GeneratedValue(generator = "uuid")
	@GenericGenerator(name = "uuid", strategy = "uuid2")
	@Column(name = "metaId", unique = true)
	@JsonIgnore
	private String metaId;
	
	@JsonProperty("region")
	private String region;
	
	@JsonProperty("long_synopsis")
	private String longSynopsis;
	
	@JsonProperty("meta_desc")
	private String metaDesc;
	
	@Column
	@ElementCollection(targetClass = String.class)
	@JsonProperty("tags")
	private List<String> tags;

	public Metadata() {
		super();
	}

	public Metadata(String region, String longSynopsis, String metaDesc, List<String> tags) {
		super();
		this.region = region;
		this.longSynopsis = longSynopsis;
		this.metaDesc = metaDesc;
		this.tags = tags;
	}

	public String getMetaId() {
		return metaId;
	}

	public void setMetaId(String metaId) {
		this.metaId = metaId;
	}

	public String getRegion() {
		return region;
	}

	public void setRegion(String region) {
		this.region = region;
	}

	public String getLongSynopsis() {
		return longSynopsis;
	}

	public void setLongSynopsis(String longSynopsis) {
		this.longSynopsis = longSynopsis;
	}

	public String getMetaDesc() {
		return metaDesc;
	}

	public void setMetaDesc(String metaDesc) {
		this.metaDesc = metaDesc;
	}

	public List<String> getTags() {
		return tags;
	}

	public void setTags(List<String> tags) {
		this.tags = tags;
	}
}

请协助您使用注释,以基于子类中的字段获取数据进行查询。

0 个答案:

没有答案