mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-22 20:12:11 +00:00
Polishing.
This commit is contained in:
parent
496b8d62a4
commit
c96423d5ba
@ -51,15 +51,7 @@ import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverte
|
|||||||
import org.springframework.data.elasticsearch.core.document.Document;
|
import org.springframework.data.elasticsearch.core.document.Document;
|
||||||
import org.springframework.data.elasticsearch.core.document.SearchDocumentResponse;
|
import org.springframework.data.elasticsearch.core.document.SearchDocumentResponse;
|
||||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||||
import org.springframework.data.elasticsearch.core.query.BaseQueryBuilder;
|
import org.springframework.data.elasticsearch.core.query.*;
|
||||||
import org.springframework.data.elasticsearch.core.query.BulkOptions;
|
|
||||||
import org.springframework.data.elasticsearch.core.query.ByQueryResponse;
|
|
||||||
import org.springframework.data.elasticsearch.core.query.DeleteQuery;
|
|
||||||
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
|
||||||
import org.springframework.data.elasticsearch.core.query.MoreLikeThisQuery;
|
|
||||||
import org.springframework.data.elasticsearch.core.query.Query;
|
|
||||||
import org.springframework.data.elasticsearch.core.query.SearchTemplateQuery;
|
|
||||||
import org.springframework.data.elasticsearch.core.query.UpdateQuery;
|
|
||||||
import org.springframework.data.elasticsearch.core.query.UpdateResponse;
|
import org.springframework.data.elasticsearch.core.query.UpdateResponse;
|
||||||
import org.springframework.data.elasticsearch.core.reindex.ReindexRequest;
|
import org.springframework.data.elasticsearch.core.reindex.ReindexRequest;
|
||||||
import org.springframework.data.elasticsearch.core.reindex.ReindexResponse;
|
import org.springframework.data.elasticsearch.core.reindex.ReindexResponse;
|
||||||
@ -517,18 +509,19 @@ public class ElasticsearchTemplate extends AbstractElasticsearchTemplate {
|
|||||||
|
|
||||||
private List<SearchHits<?>> multiSearch(List<MultiSearchQueryParameter> multiSearchQueryParameters,
|
private List<SearchHits<?>> multiSearch(List<MultiSearchQueryParameter> multiSearchQueryParameters,
|
||||||
boolean isSearchTemplateQuery) {
|
boolean isSearchTemplateQuery) {
|
||||||
return isSearchTemplateQuery ?
|
return isSearchTemplateQuery ? doMultiTemplateSearch(multiSearchQueryParameters.stream()
|
||||||
doMultiTemplateSearch(multiSearchQueryParameters.stream()
|
.map(p -> new MultiSearchTemplateQueryParameter((SearchTemplateQuery) p.query, p.clazz, p.index))
|
||||||
.map(p -> new MultiSearchTemplateQueryParameter((SearchTemplateQuery) p.query, p.clazz, p.index))
|
.toList())
|
||||||
.toList())
|
|
||||||
: doMultiSearch(multiSearchQueryParameters);
|
: doMultiSearch(multiSearchQueryParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<SearchHits<?>> doMultiTemplateSearch(List<MultiSearchTemplateQueryParameter> mSearchTemplateQueryParameters) {
|
private List<SearchHits<?>> doMultiTemplateSearch(
|
||||||
|
List<MultiSearchTemplateQueryParameter> mSearchTemplateQueryParameters) {
|
||||||
MsearchTemplateRequest request = requestConverter.searchMsearchTemplateRequest(mSearchTemplateQueryParameters,
|
MsearchTemplateRequest request = requestConverter.searchMsearchTemplateRequest(mSearchTemplateQueryParameters,
|
||||||
routingResolver.getRouting());
|
routingResolver.getRouting());
|
||||||
|
|
||||||
MsearchTemplateResponse<EntityAsMap> response = execute(client -> client.msearchTemplate(request, EntityAsMap.class));
|
MsearchTemplateResponse<EntityAsMap> response = execute(
|
||||||
|
client -> client.msearchTemplate(request, EntityAsMap.class));
|
||||||
List<MultiSearchResponseItem<EntityAsMap>> responseItems = response.responses();
|
List<MultiSearchResponseItem<EntityAsMap>> responseItems = response.responses();
|
||||||
|
|
||||||
Assert.isTrue(mSearchTemplateQueryParameters.size() == responseItems.size(),
|
Assert.isTrue(mSearchTemplateQueryParameters.size() == responseItems.size(),
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -639,7 +639,7 @@ class RequestConverter {
|
|||||||
Object queryObject = query.getObject();
|
Object queryObject = query.getObject();
|
||||||
|
|
||||||
if (queryObject != null) {
|
if (queryObject != null) {
|
||||||
builder
|
builder
|
||||||
.id(StringUtils.hasText(query.getId()) ? query.getId() : getPersistentEntityId(queryObject))
|
.id(StringUtils.hasText(query.getId()) ? query.getId() : getPersistentEntityId(queryObject))
|
||||||
.document(elasticsearchConverter.mapObject(queryObject));
|
.document(elasticsearchConverter.mapObject(queryObject));
|
||||||
} else if (query.getSource() != null) {
|
} else if (query.getSource() != null) {
|
||||||
@ -969,7 +969,7 @@ class RequestConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public DeleteByQueryRequest documentDeleteByQueryRequest(DeleteQuery query, @Nullable String routing, Class<?> clazz,
|
public DeleteByQueryRequest documentDeleteByQueryRequest(DeleteQuery query, @Nullable String routing, Class<?> clazz,
|
||||||
IndexCoordinates index, @Nullable RefreshPolicy refreshPolicy) {
|
IndexCoordinates index, @Nullable RefreshPolicy refreshPolicy) {
|
||||||
Assert.notNull(query, "query must not be null");
|
Assert.notNull(query, "query must not be null");
|
||||||
Assert.notNull(index, "index must not be null");
|
Assert.notNull(index, "index must not be null");
|
||||||
|
|
||||||
@ -978,7 +978,7 @@ class RequestConverter {
|
|||||||
.query(getQuery(query.getQuery(), clazz))//
|
.query(getQuery(query.getQuery(), clazz))//
|
||||||
.refresh(deleteByQueryRefresh(refreshPolicy))
|
.refresh(deleteByQueryRefresh(refreshPolicy))
|
||||||
.requestsPerSecond(query.getRequestsPerSecond())
|
.requestsPerSecond(query.getRequestsPerSecond())
|
||||||
.maxDocs(query.getMaxDocs())
|
.maxDocs(query.getMaxDocs())
|
||||||
.scroll(time(query.getScroll()))
|
.scroll(time(query.getScroll()))
|
||||||
.scrollSize(query.getScrollSize());
|
.scrollSize(query.getScrollSize());
|
||||||
|
|
||||||
@ -1022,8 +1022,7 @@ class RequestConverter {
|
|||||||
|
|
||||||
return sortField.field() + ":" + order;
|
return sortField.field() + ":" + order;
|
||||||
})
|
})
|
||||||
.collect(Collectors.toList())
|
.collect(Collectors.toList()));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dqb.allowNoIndices(query.getAllowNoIndices())
|
dqb.allowNoIndices(query.getAllowNoIndices())
|
||||||
|
@ -504,25 +504,27 @@ final class TypeUtils {
|
|||||||
return mappedParams;
|
return mappedParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a spring-data-elasticsearch operator to an Elasticsearch operator.
|
* Convert a spring-data-elasticsearch operator to an Elasticsearch operator.
|
||||||
*
|
*
|
||||||
* @param operator spring-data-elasticsearch operator.
|
* @param operator spring-data-elasticsearch operator.
|
||||||
* @return an Elasticsearch Operator.
|
* @return an Elasticsearch Operator.
|
||||||
*/
|
* @since 5.3
|
||||||
@Nullable
|
*/
|
||||||
static Operator operator(@Nullable OperatorType operator) {
|
@Nullable
|
||||||
return operator != null ? Operator.valueOf(operator.name()) : null;
|
static Operator operator(@Nullable OperatorType operator) {
|
||||||
}
|
return operator != null ? Operator.valueOf(operator.name()) : null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a spring-data-elasticsearch {@literal conflicts} to an Elasticsearch {@literal conflicts}.
|
* Convert a spring-data-elasticsearch {@literal conflicts} to an Elasticsearch {@literal conflicts}.
|
||||||
*
|
*
|
||||||
* @param conflicts spring-data-elasticsearch {@literal conflicts}.
|
* @param conflicts spring-data-elasticsearch {@literal conflicts}.
|
||||||
* @return an Elasticsearch {@literal conflicts}.
|
* @return an Elasticsearch {@literal conflicts}.
|
||||||
*/
|
* @since 5.3
|
||||||
@Nullable
|
*/
|
||||||
static Conflicts conflicts(@Nullable ConflictsType conflicts) {
|
@Nullable
|
||||||
return conflicts != null ? Conflicts.valueOf(conflicts.name()) : null;
|
static Conflicts conflicts(@Nullable ConflictsType conflicts) {
|
||||||
}
|
return conflicts != null ? Conflicts.valueOf(conflicts.name()) : null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core;
|
package org.springframework.data.elasticsearch.core;
|
||||||
|
|
||||||
import org.springframework.data.elasticsearch.core.query.DeleteQuery;
|
|
||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
import reactor.core.publisher.Sinks;
|
import reactor.core.publisher.Sinks;
|
||||||
@ -47,6 +46,7 @@ import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersiste
|
|||||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||||
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
|
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
|
||||||
import org.springframework.data.elasticsearch.core.query.ByQueryResponse;
|
import org.springframework.data.elasticsearch.core.query.ByQueryResponse;
|
||||||
|
import org.springframework.data.elasticsearch.core.query.DeleteQuery;
|
||||||
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
||||||
import org.springframework.data.elasticsearch.core.query.Query;
|
import org.springframework.data.elasticsearch.core.query.Query;
|
||||||
import org.springframework.data.elasticsearch.core.query.SeqNoPrimaryTerm;
|
import org.springframework.data.elasticsearch.core.query.SeqNoPrimaryTerm;
|
||||||
|
@ -289,7 +289,7 @@ public interface DocumentOperations {
|
|||||||
*
|
*
|
||||||
* @param query query defining the objects
|
* @param query query defining the objects
|
||||||
* @param clazz The entity class must be annotated with
|
* @param clazz The entity class must be annotated with
|
||||||
* {@link org.springframework.data.elasticsearch.annotations.Document}
|
* {@link org.springframework.data.elasticsearch.annotations.Document}
|
||||||
* @return response with detailed information
|
* @return response with detailed information
|
||||||
* @since 5.3
|
* @since 5.3
|
||||||
*/
|
*/
|
||||||
@ -312,7 +312,7 @@ public interface DocumentOperations {
|
|||||||
*
|
*
|
||||||
* @param query query defining the objects
|
* @param query query defining the objects
|
||||||
* @param clazz The entity class must be annotated with
|
* @param clazz The entity class must be annotated with
|
||||||
* {@link org.springframework.data.elasticsearch.annotations.Document}
|
* {@link org.springframework.data.elasticsearch.annotations.Document}
|
||||||
* @param index the index from which to delete
|
* @param index the index from which to delete
|
||||||
* @return response with detailed information
|
* @return response with detailed information
|
||||||
* @since 5.3
|
* @since 5.3
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.core;
|
package org.springframework.data.elasticsearch.core;
|
||||||
|
|
||||||
import org.springframework.data.elasticsearch.core.query.DeleteQuery;
|
|
||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
@ -26,6 +25,7 @@ import java.util.List;
|
|||||||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
|
||||||
import org.springframework.data.elasticsearch.core.query.BulkOptions;
|
import org.springframework.data.elasticsearch.core.query.BulkOptions;
|
||||||
import org.springframework.data.elasticsearch.core.query.ByQueryResponse;
|
import org.springframework.data.elasticsearch.core.query.ByQueryResponse;
|
||||||
|
import org.springframework.data.elasticsearch.core.query.DeleteQuery;
|
||||||
import org.springframework.data.elasticsearch.core.query.Query;
|
import org.springframework.data.elasticsearch.core.query.Query;
|
||||||
import org.springframework.data.elasticsearch.core.query.UpdateQuery;
|
import org.springframework.data.elasticsearch.core.query.UpdateQuery;
|
||||||
import org.springframework.data.elasticsearch.core.query.UpdateResponse;
|
import org.springframework.data.elasticsearch.core.query.UpdateResponse;
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -19,7 +19,8 @@ package org.springframework.data.elasticsearch.core.query.types;
|
|||||||
* Define the types of conflicts that occur when a query encounters version conflicts.
|
* Define the types of conflicts that occur when a query encounters version conflicts.
|
||||||
*
|
*
|
||||||
* @author Aouichaoui Youssef
|
* @author Aouichaoui Youssef
|
||||||
|
* @since 5.3
|
||||||
*/
|
*/
|
||||||
public enum ConflictsType {
|
public enum ConflictsType {
|
||||||
Abort, Proceed
|
Abort, Proceed
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,8 @@ package org.springframework.data.elasticsearch.core.query.types;
|
|||||||
* Define the default operator for a query string query.
|
* Define the default operator for a query string query.
|
||||||
*
|
*
|
||||||
* @author Aouichaoui Youssef
|
* @author Aouichaoui Youssef
|
||||||
|
* @since 5.3
|
||||||
*/
|
*/
|
||||||
public enum OperatorType {
|
public enum OperatorType {
|
||||||
And, Or
|
And, Or
|
||||||
}
|
}
|
||||||
|
@ -19,16 +19,11 @@ import static java.util.Collections.*;
|
|||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
import static org.springframework.data.elasticsearch.annotations.Document.VersionType.*;
|
import static org.springframework.data.elasticsearch.annotations.Document.VersionType.*;
|
||||||
import static org.springframework.data.elasticsearch.annotations.FieldType.*;
|
import static org.springframework.data.elasticsearch.annotations.FieldType.*;
|
||||||
import static org.springframework.data.elasticsearch.annotations.FieldType.Integer;
|
|
||||||
import static org.springframework.data.elasticsearch.core.document.Document.*;
|
import static org.springframework.data.elasticsearch.core.document.Document.*;
|
||||||
import static org.springframework.data.elasticsearch.core.query.StringQuery.*;
|
import static org.springframework.data.elasticsearch.core.query.StringQuery.*;
|
||||||
import static org.springframework.data.elasticsearch.utils.IdGenerator.*;
|
import static org.springframework.data.elasticsearch.utils.IdGenerator.*;
|
||||||
import static org.springframework.data.elasticsearch.utils.IndexBuilder.*;
|
import static org.springframework.data.elasticsearch.utils.IndexBuilder.*;
|
||||||
|
|
||||||
import java.lang.Double;
|
|
||||||
import java.lang.Integer;
|
|
||||||
import java.lang.Long;
|
|
||||||
import java.lang.Object;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
@ -2976,8 +2971,8 @@ public abstract class ElasticsearchIntegrationTests {
|
|||||||
.build();
|
.build();
|
||||||
Query query = getBuilderWithTermQuery("message", "message") //
|
Query query = getBuilderWithTermQuery("message", "message") //
|
||||||
.withHighlightQuery(
|
.withHighlightQuery(
|
||||||
new HighlightQuery(new Highlight(singletonList(new HighlightField("message", sameHighlightQuery))), HighlightEntity.class)
|
new HighlightQuery(new Highlight(singletonList(new HighlightField("message", sameHighlightQuery))),
|
||||||
)
|
HighlightEntity.class))
|
||||||
.build();
|
.build();
|
||||||
SearchHits<HighlightEntity> searchHits = operations.search(query, HighlightEntity.class, index);
|
SearchHits<HighlightEntity> searchHits = operations.search(query, HighlightEntity.class, index);
|
||||||
|
|
||||||
@ -3002,8 +2997,9 @@ public abstract class ElasticsearchIntegrationTests {
|
|||||||
// highlight_query in field
|
// highlight_query in field
|
||||||
Query highlightQueryInField = getBuilderWithTermQuery("message", "message") //
|
Query highlightQueryInField = getBuilderWithTermQuery("message", "message") //
|
||||||
.withHighlightQuery(
|
.withHighlightQuery(
|
||||||
new HighlightQuery(new Highlight(singletonList(new HighlightField("message", differentHighlightQueryInField))), HighlightEntity.class)
|
new HighlightQuery(
|
||||||
)
|
new Highlight(singletonList(new HighlightField("message", differentHighlightQueryInField))),
|
||||||
|
HighlightEntity.class))
|
||||||
.build();
|
.build();
|
||||||
assertThatHighlightFieldsIsDifferentFromHighlightQuery(highlightQueryInField, index);
|
assertThatHighlightFieldsIsDifferentFromHighlightQuery(highlightQueryInField, index);
|
||||||
}
|
}
|
||||||
@ -3019,8 +3015,9 @@ public abstract class ElasticsearchIntegrationTests {
|
|||||||
// highlight_query in param
|
// highlight_query in param
|
||||||
Query highlightQueryInParam = getBuilderWithTermQuery("message", "message") //
|
Query highlightQueryInParam = getBuilderWithTermQuery("message", "message") //
|
||||||
.withHighlightQuery(
|
.withHighlightQuery(
|
||||||
new HighlightQuery(new Highlight(differentHighlightQueryInParam, singletonList(new HighlightField("message"))), HighlightEntity.class)
|
new HighlightQuery(
|
||||||
)
|
new Highlight(differentHighlightQueryInParam, singletonList(new HighlightField("message"))),
|
||||||
|
HighlightEntity.class))
|
||||||
.build();
|
.build();
|
||||||
assertThatHighlightFieldsIsDifferentFromHighlightQuery(highlightQueryInParam, index);
|
assertThatHighlightFieldsIsDifferentFromHighlightQuery(highlightQueryInParam, index);
|
||||||
}
|
}
|
||||||
@ -3035,8 +3032,9 @@ public abstract class ElasticsearchIntegrationTests {
|
|||||||
// highlight_query in param
|
// highlight_query in param
|
||||||
Query differentHighlightQueryUsingCriteria = getBuilderWithTermQuery("message", "message") //
|
Query differentHighlightQueryUsingCriteria = getBuilderWithTermQuery("message", "message") //
|
||||||
.withHighlightQuery(
|
.withHighlightQuery(
|
||||||
new HighlightQuery(new Highlight(criteriaHighlightQueryInParam, singletonList(new HighlightField("message"))), HighlightEntity.class)
|
new HighlightQuery(
|
||||||
)
|
new Highlight(criteriaHighlightQueryInParam, singletonList(new HighlightField("message"))),
|
||||||
|
HighlightEntity.class))
|
||||||
.build();
|
.build();
|
||||||
assertThatHighlightFieldsIsDifferentFromHighlightQuery(differentHighlightQueryUsingCriteria, index);
|
assertThatHighlightFieldsIsDifferentFromHighlightQuery(differentHighlightQueryUsingCriteria, index);
|
||||||
}
|
}
|
||||||
@ -3055,14 +3053,13 @@ public abstract class ElasticsearchIntegrationTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"""
|
"""))
|
||||||
))
|
|
||||||
.build();
|
.build();
|
||||||
// highlight_query in param
|
// highlight_query in param
|
||||||
Query differentHighlightQueryUsingStringQuery = getBuilderWithTermQuery("message", "message") //
|
Query differentHighlightQueryUsingStringQuery = getBuilderWithTermQuery("message", "message") //
|
||||||
.withHighlightQuery(
|
.withHighlightQuery(
|
||||||
new HighlightQuery(new Highlight(stringHighlightQueryInParam, singletonList(new HighlightField("message"))), HighlightEntity.class)
|
new HighlightQuery(new Highlight(stringHighlightQueryInParam, singletonList(new HighlightField("message"))),
|
||||||
)
|
HighlightEntity.class))
|
||||||
.build();
|
.build();
|
||||||
assertThatHighlightFieldsIsDifferentFromHighlightQuery(differentHighlightQueryUsingStringQuery, index);
|
assertThatHighlightFieldsIsDifferentFromHighlightQuery(differentHighlightQueryUsingStringQuery, index);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user