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