mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-23 12:32:10 +00:00
DATAES-14 - Dynamic Search Type Support
added searchType parameter to NativeSearchQueryBuilder
This commit is contained in:
parent
08cdcc5c4c
commit
d4f2001b46
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -20,6 +20,7 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.elasticsearch.action.search.SearchType;
|
||||
import org.elasticsearch.index.query.FilterBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.search.highlight.HighlightBuilder;
|
||||
@ -49,6 +50,7 @@ public class NativeSearchQueryBuilder {
|
||||
private float minScore;
|
||||
private Collection<String> ids;
|
||||
private String route;
|
||||
private SearchType searchType;
|
||||
|
||||
public NativeSearchQueryBuilder withQuery(QueryBuilder queryBuilder) {
|
||||
this.queryBuilder = queryBuilder;
|
||||
@ -110,6 +112,11 @@ public class NativeSearchQueryBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public NativeSearchQueryBuilder withSearchType(SearchType searchType) {
|
||||
this.searchType = searchType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NativeSearchQuery build() {
|
||||
NativeSearchQuery nativeSearchQuery = new NativeSearchQuery(queryBuilder, filterBuilder, sortBuilders, highlightFields);
|
||||
if (pageable != null) {
|
||||
@ -144,6 +151,10 @@ public class NativeSearchQueryBuilder {
|
||||
nativeSearchQuery.setRoute(route);
|
||||
}
|
||||
|
||||
if (searchType != null) {
|
||||
nativeSearchQuery.setSearchType(searchType);
|
||||
}
|
||||
|
||||
return nativeSearchQuery;
|
||||
}
|
||||
}
|
||||
|
@ -1147,16 +1147,13 @@ public class ElasticsearchTemplateTests {
|
||||
public void shouldIndexSampleEntityWithIndexAndTypeAtRuntime() {
|
||||
// given
|
||||
String documentId = randomNumeric(5);
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(documentId);
|
||||
sampleEntity.setMessage("some message");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
SampleEntity sampleEntity = new SampleEntityBuilder(documentId)
|
||||
.message("some message")
|
||||
.version(System.currentTimeMillis()).build();
|
||||
|
||||
IndexQuery indexQuery = new IndexQuery();
|
||||
indexQuery.setId(documentId);
|
||||
indexQuery.setIndexName(INDEX_NAME);
|
||||
indexQuery.setType(TYPE_NAME);
|
||||
indexQuery.setObject(sampleEntity);
|
||||
IndexQuery indexQuery = new IndexQueryBuilder().withId(documentId)
|
||||
.withIndexName(INDEX_NAME).withType(TYPE_NAME)
|
||||
.withObject(sampleEntity).build();
|
||||
|
||||
elasticsearchTemplate.index(indexQuery);
|
||||
elasticsearchTemplate.refresh(INDEX_NAME, true);
|
||||
|
Loading…
x
Reference in New Issue
Block a user