DATAES-211

changes in AliasRequest
 fix tests due to changes in mapping, geo point, alias etc
This commit is contained in:
Mohsin Husen 2016-02-16 16:07:36 +00:00
parent 95194961dc
commit 4e0cbb8966
8 changed files with 100 additions and 105 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2013 the original author or authors. * Copyright 2013-2016 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.
@ -37,6 +37,9 @@ import org.springframework.util.Assert;
* CriteriaFilterProcessor * CriteriaFilterProcessor
* *
* @author Franck Marchand * @author Franck Marchand
* @author Mohsin Husen
* @author Artur Konczak
*
*/ */
class CriteriaFilterProcessor { class CriteriaFilterProcessor {
@ -105,6 +108,7 @@ class CriteriaFilterProcessor {
} }
QueryBuilder filter = null; QueryBuilder filter = null;
//todo : expose more option for GeoPoint i.e GeoDistance.PLANE or GeoDistance.ARC
switch (key) { switch (key) {
case WITHIN: { case WITHIN: {
GeoDistanceQueryBuilder geoDistanceQueryBuilder = QueryBuilders.geoDistanceQuery(fieldName); GeoDistanceQueryBuilder geoDistanceQueryBuilder = QueryBuilders.geoDistanceQuery(fieldName);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2013-2014 the original author or authors. * Copyright 2013-2016 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.
@ -16,6 +16,7 @@
package org.springframework.data.elasticsearch.core; package org.springframework.data.elasticsearch.core;
import org.elasticsearch.action.update.UpdateResponse; import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.cluster.metadata.AliasMetaData;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter; import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity; import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
@ -25,7 +26,6 @@ import org.springframework.data.util.CloseableIterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
/** /**
* ElasticsearchOperations * ElasticsearchOperations
@ -588,7 +588,7 @@ public interface ElasticsearchOperations {
* @param indexName * @param indexName
* @return * @return
*/ */
Set<String> queryForAlias(String indexName); List<AliasMetaData> queryForAlias(String indexName);
<T> T query(SearchQuery query, ResultsExtractor<T> resultsExtractor); <T> T query(SearchQuery query, ResultsExtractor<T> resultsExtractor);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2013-2014 the original author or authors. * Copyright 2013-2016 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.
@ -32,7 +32,7 @@ import java.util.*;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.elasticsearch.action.ListenableActionFuture; import org.elasticsearch.action.ListenableActionFuture;
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest; import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest; import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest;
@ -57,13 +57,13 @@ import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.client.Requests; import org.elasticsearch.client.Requests;
import org.elasticsearch.cluster.metadata.AliasAction; import org.elasticsearch.cluster.metadata.AliasAction;
import org.elasticsearch.cluster.metadata.AliasMetaData;
import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.query.MoreLikeThisQueryBuilder; import org.elasticsearch.index.query.MoreLikeThisQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.script.Script;
import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
import org.elasticsearch.search.highlight.HighlightBuilder; import org.elasticsearch.search.highlight.HighlightBuilder;
@ -642,6 +642,7 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
@Override @Override
public <T> void delete(DeleteQuery deleteQuery, Class<T> clazz) { public <T> void delete(DeleteQuery deleteQuery, Class<T> clazz) {
//TODO : clean up expose parameter for scan and scroll
String iName = deleteQuery.getIndex(); String iName = deleteQuery.getIndex();
String tName = deleteQuery.getType(); String tName = deleteQuery.getType();
if(clazz!=null){ if(clazz!=null){
@ -656,37 +657,46 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(deleteQuery.getQuery()) SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(deleteQuery.getQuery())
.withIndices(indexName) .withIndices(indexName)
.withTypes(typeName) .withTypes(typeName)
//TOD: ako - check that id is all the time avaialable
//.withFields("_id")
.withPageable(new PageRequest(0, 1000)) .withPageable(new PageRequest(0, 1000))
.build(); .build();
final String scrollId = scan(searchQuery, 10000, true); final String scrollId = scan(searchQuery, 10000, true);
final BulkRequestBuilder bulkRequestBuilder = client.prepareBulk(); final BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
boolean hasMoreRecords = true; List<String> ids = new ArrayList<String>();
while (hasMoreRecords) { boolean hasRecords = true;
final Page<Object> scroll = scroll(scrollId, 10000L, new SearchResultMapper() { while (hasRecords) {
Page<String> page = scroll(scrollId, 5000, new SearchResultMapper() {
@Override @Override
public <T> FacetedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) { public <T> FacetedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
boolean hasItems = false; List<String> result = new ArrayList<String>();
for (SearchHit searchHit : response.getHits()) { for (SearchHit searchHit : response.getHits()) {
hasItems = true; String id = searchHit.getId();
bulkRequestBuilder.add(client.prepareDelete(indexName, typeName, searchHit.getId())); result.add(id);
} }
if(hasItems){
return new FacetedPageImpl<T>((List<T>)Arrays.asList(new Object())); if (result.size() > 0) {
return new FacetedPageImpl<T>((List<T>) result);
} }
return null; return null;
} }
}); });
if (scroll == null) { if (page != null && page.getContent().size() > 0) {
hasMoreRecords = false; ids.addAll(page.getContent());
} else {
hasRecords = false;
} }
} }
if(bulkRequestBuilder.numberOfActions()>0) {
for(String id : ids) {
bulkRequestBuilder.add(client.prepareDelete(indexName, typeName, id));
}
if(bulkRequestBuilder.numberOfActions() > 0) {
bulkRequestBuilder.execute().actionGet(); bulkRequestBuilder.execute().actionGet();
} }
refresh(indexName, false);
} }
@Override @Override
@ -795,7 +805,7 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
@Override @Override
public <T> Page<T> moreLikeThis(MoreLikeThisQuery query, Class<T> clazz) { public <T> Page<T> moreLikeThis(MoreLikeThisQuery query, Class<T> clazz) {
int startRecord = 0; //todo : clean up
ElasticsearchPersistentEntity persistentEntity = getPersistentEntityFor(clazz); ElasticsearchPersistentEntity persistentEntity = getPersistentEntityFor(clazz);
String indexName = isNotBlank(query.getIndexName()) ? query.getIndexName() : persistentEntity.getIndexName(); String indexName = isNotBlank(query.getIndexName()) ? query.getIndexName() : persistentEntity.getIndexName();
String type = isNotBlank(query.getType()) ? query.getType() : persistentEntity.getIndexType(); String type = isNotBlank(query.getType()) ? query.getType() : persistentEntity.getIndexType();
@ -805,60 +815,35 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
Assert.notNull(query.getId(), "No document id defined for MoreLikeThisQuery"); Assert.notNull(query.getId(), "No document id defined for MoreLikeThisQuery");
final MoreLikeThisQueryBuilder.Item item = new MoreLikeThisQueryBuilder.Item(indexName, type, query.getId()); final MoreLikeThisQueryBuilder.Item item = new MoreLikeThisQueryBuilder.Item(indexName, type, query.getId());
final NativeSearchQuery build = new NativeSearchQueryBuilder().withQuery(moreLikeThisQuery().addLikeItem(item)).build(); MoreLikeThisQueryBuilder moreLikeThisQueryBuilder = moreLikeThisQuery().addLikeItem(item);
return queryForPage(build,clazz);
//TODO: Mohins - set all other params for moreLikeThis
/* MoreLikeThisRequestBuilder requestBuilder = client.prepareMoreLikeThis(indexName, type, query.getId());
if (query.getPageable() != null) {
startRecord = query.getPageable().getPageNumber() * query.getPageable().getPageSize();
requestBuilder.setSearchSize(query.getPageable().getPageSize());
}
requestBuilder.setSearchFrom(startRecord);
if (isNotEmpty(query.getSearchIndices())) {
requestBuilder.setSearchIndices(toArray(query.getSearchIndices()));
}
if (isNotEmpty(query.getSearchTypes())) {
requestBuilder.setSearchTypes(toArray(query.getSearchTypes()));
}
if (isNotEmpty(query.getFields())) {
requestBuilder.setField(toArray(query.getFields()));
}
if (isNotBlank(query.getRouting())) {
requestBuilder.setRouting(query.getRouting());
}
if (query.getPercentTermsToMatch() != null) {
requestBuilder.setPercentTermsToMatch(query.getPercentTermsToMatch());
}
if (query.getMinTermFreq() != null) { if (query.getMinTermFreq() != null) {
requestBuilder.setMinTermFreq(query.getMinTermFreq()); moreLikeThisQueryBuilder.minTermFreq(query.getMinTermFreq());
} }
if (query.getMaxQueryTerms() != null) { if (query.getMaxQueryTerms() != null) {
requestBuilder.maxQueryTerms(query.getMaxQueryTerms()); moreLikeThisQueryBuilder.maxQueryTerms(query.getMaxQueryTerms());
} }
if (isNotEmpty(query.getStopWords())) { if (isNotEmpty(query.getStopWords())) {
requestBuilder.setStopWords(toArray(query.getStopWords())); moreLikeThisQueryBuilder.stopWords(toArray(query.getStopWords()));
} }
if (query.getMinDocFreq() != null) { if (query.getMinDocFreq() != null) {
requestBuilder.setMinDocFreq(query.getMinDocFreq()); moreLikeThisQueryBuilder.minDocFreq(query.getMinDocFreq());
} }
if (query.getMaxDocFreq() != null) { if (query.getMaxDocFreq() != null) {
requestBuilder.setMaxDocFreq(query.getMaxDocFreq()); moreLikeThisQueryBuilder.maxDocFreq(query.getMaxDocFreq());
} }
if (query.getMinWordLen() != null) { if (query.getMinWordLen() != null) {
requestBuilder.setMinWordLen(query.getMinWordLen()); moreLikeThisQueryBuilder.minWordLength(query.getMinWordLen());
} }
if (query.getMaxWordLen() != null) { if (query.getMaxWordLen() != null) {
requestBuilder.setMaxWordLen(query.getMaxWordLen()); moreLikeThisQueryBuilder.maxWordLength(query.getMaxWordLen());
} }
if (query.getBoostTerms() != null) { if (query.getBoostTerms() != null) {
requestBuilder.setBoostTerms(query.getBoostTerms()); moreLikeThisQueryBuilder.boostTerms(query.getBoostTerms());
} }
SearchResponse response = getSearchResponse(requestBuilder.execute()); final NativeSearchQuery build = new NativeSearchQueryBuilder().withQuery(moreLikeThisQueryBuilder).build();
return resultsMapper.mapResults(response, clazz, query.getPageable());*/ return queryForPage(build,clazz);
} }
private SearchResponse doSearch(SearchRequestBuilder searchRequest, SearchQuery searchQuery) { private SearchResponse doSearch(SearchRequestBuilder searchRequest, SearchQuery searchQuery) {
@ -1052,11 +1037,13 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
} }
} }
//TODO : remove or waitForOperation
@Override @Override
public void refresh(String indexName, boolean waitForOperation) { public void refresh(String indexName, boolean waitForOperation) {
client.admin().indices().refresh(refreshRequest(indexName)).actionGet(); client.admin().indices().refresh(refreshRequest(indexName)).actionGet();
} }
//TODO : remove or waitForOperation
@Override @Override
public <T> void refresh(Class<T> clazz, boolean waitForOperation) { public <T> void refresh(Class<T> clazz, boolean waitForOperation) {
ElasticsearchPersistentEntity persistentEntity = getPersistentEntityFor(clazz); ElasticsearchPersistentEntity persistentEntity = getPersistentEntityFor(clazz);
@ -1092,13 +1079,9 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
} }
@Override @Override
public Set<String> queryForAlias(String indexName) { public List<AliasMetaData> queryForAlias(String indexName) {
ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest() return client.admin().indices().getAliases(new GetAliasesRequest().indices(indexName))
.routingTable(true).nodes(true).indices(indexName); .actionGet().getAliases().get(indexName);
//TODO: ako check how to find aliases for index
/* Iterator<String> iterator = client.admin().cluster().state(clusterStateRequest).actionGet().getState().getMetaData().aliases().keysIt();
return newHashSet(iterator);*/
return null;
} }
@Override @Override

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2014-2015 the original author or authors. * Copyright 2014-2016 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.
@ -19,11 +19,10 @@ import static org.apache.commons.lang.RandomStringUtils.*;
import static org.elasticsearch.index.query.QueryBuilders.*; import static org.elasticsearch.index.query.QueryBuilders.*;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import org.elasticsearch.cluster.metadata.AliasMetaData;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -40,7 +39,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ContextConfiguration("classpath:elasticsearch-template-test.xml") @ContextConfiguration("classpath:elasticsearch-template-test.xml")
public class AliasTests { public class AliasTests {
private static final String INDEX_NAME = "test-alias-index"; private static final String INDEX_NAME_1 = "test-alias-index-1";
private static final String INDEX_NAME_2 = "test-alias-index-2";
private static final String TYPE_NAME = "test-alias-type"; private static final String TYPE_NAME = "test-alias-type";
@Autowired @Autowired
@ -54,9 +54,13 @@ public class AliasTests {
settings.put("index.number_of_shards", "2"); settings.put("index.number_of_shards", "2");
settings.put("index.store.type", "fs"); settings.put("index.store.type", "fs");
elasticsearchTemplate.deleteIndex(INDEX_NAME); elasticsearchTemplate.deleteIndex(INDEX_NAME_1);
elasticsearchTemplate.createIndex(INDEX_NAME, settings); elasticsearchTemplate.createIndex(INDEX_NAME_1, settings);
elasticsearchTemplate.refresh(INDEX_NAME, true); elasticsearchTemplate.refresh(INDEX_NAME_1, true);
elasticsearchTemplate.deleteIndex(INDEX_NAME_2);
elasticsearchTemplate.createIndex(INDEX_NAME_2, settings);
elasticsearchTemplate.refresh(INDEX_NAME_2, true);
} }
@Test @Test
@ -64,34 +68,33 @@ public class AliasTests {
// given // given
String aliasName = "test-alias"; String aliasName = "test-alias";
AliasQuery aliasQuery = new AliasBuilder() AliasQuery aliasQuery = new AliasBuilder()
.withIndexName(INDEX_NAME) .withIndexName(INDEX_NAME_1)
.withAliasName(aliasName).build(); .withAliasName(aliasName).build();
// when // when
elasticsearchTemplate.addAlias(aliasQuery); elasticsearchTemplate.addAlias(aliasQuery);
// then // then
Set<String> aliases = elasticsearchTemplate.queryForAlias(INDEX_NAME); List<AliasMetaData> aliases = elasticsearchTemplate.queryForAlias(INDEX_NAME_1);
assertThat(aliases, is(notNullValue())); assertThat(aliases, is(notNullValue()));
assertThat(aliases.contains(aliasName), is(true)); assertThat(aliases.get(0).alias(), is(aliasName));
} }
@Test @Test
public void shouldRemoveAlias() { public void shouldRemoveAlias() {
// given // given
String indexName = INDEX_NAME; String indexName = INDEX_NAME_1;
String aliasName = "test-alias"; String aliasName = "test-alias";
AliasQuery aliasQuery = new AliasBuilder() AliasQuery aliasQuery = new AliasBuilder()
.withIndexName(indexName) .withIndexName(indexName)
.withAliasName(aliasName).build(); .withAliasName(aliasName).build();
// when // when
elasticsearchTemplate.addAlias(aliasQuery); elasticsearchTemplate.addAlias(aliasQuery);
Set<String> aliases = elasticsearchTemplate.queryForAlias(indexName); List<AliasMetaData> aliases = elasticsearchTemplate.queryForAlias(indexName);
assertThat(aliases, is(notNullValue())); assertThat(aliases, is(notNullValue()));
assertThat(aliases.contains(aliasName), is(true)); assertThat(aliases.get(0).alias(), is(aliasName));
// then // then
elasticsearchTemplate.removeAlias(aliasQuery); elasticsearchTemplate.removeAlias(aliasQuery);
aliases = elasticsearchTemplate.queryForAlias(indexName); aliases = elasticsearchTemplate.queryForAlias(indexName);
assertThat(aliases, is(notNullValue())); assertThat(aliases, is(nullValue()));
assertThat(aliases.size(), is(0));
} }
/* /*
@ -100,7 +103,7 @@ public class AliasTests {
@Test @Test
public void shouldAddAliasWithGivenRoutingValue() { public void shouldAddAliasWithGivenRoutingValue() {
//given //given
String indexName = INDEX_NAME; String indexName = INDEX_NAME_1;
String alias = "test-alias"; String alias = "test-alias";
AliasQuery aliasQuery = new AliasBuilder() AliasQuery aliasQuery = new AliasBuilder()
@ -124,15 +127,17 @@ public class AliasTests {
.build(); .build();
elasticsearchTemplate.index(indexQuery); elasticsearchTemplate.index(indexQuery);
elasticsearchTemplate.refresh(INDEX_NAME, true); elasticsearchTemplate.refresh(INDEX_NAME_1, true);
SearchQuery query = new NativeSearchQueryBuilder().withQuery(matchAllQuery()) SearchQuery query = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
.withIndices(alias).withTypes(TYPE_NAME).build(); .withIndices(alias).withTypes(TYPE_NAME).build();
long count = elasticsearchTemplate.count(query); long count = elasticsearchTemplate.count(query);
//then //then
Set<String> aliases = elasticsearchTemplate.queryForAlias(INDEX_NAME); List<AliasMetaData> aliases = elasticsearchTemplate.queryForAlias(INDEX_NAME_1);
assertThat(aliases, is(notNullValue())); assertThat(aliases, is(notNullValue()));
assertThat(aliases.contains(alias), is(true)); assertThat(aliases.get(0).alias(), is(alias));
assertThat(aliases.get(0).searchRouting(), is("0"));
assertThat(aliases.get(0).indexRouting(), is("0"));
assertThat(count, is(1L)); assertThat(count, is(1L));
//cleanup //cleanup
@ -153,12 +158,12 @@ public class AliasTests {
String alias2 = "test-alias-2"; String alias2 = "test-alias-2";
AliasQuery aliasQuery1 = new AliasBuilder() AliasQuery aliasQuery1 = new AliasBuilder()
.withIndexName(INDEX_NAME) .withIndexName(INDEX_NAME_1)
.withAliasName(alias1) .withAliasName(alias1)
.withIndexRouting("0").build(); .withIndexRouting("0").build();
AliasQuery aliasQuery2 = new AliasBuilder() AliasQuery aliasQuery2 = new AliasBuilder()
.withIndexName(INDEX_NAME) .withIndexName(INDEX_NAME_2)
.withAliasName(alias2) .withAliasName(alias2)
.withSearchRouting("1").build(); .withSearchRouting("1").build();
@ -179,15 +184,17 @@ public class AliasTests {
elasticsearchTemplate.index(indexQuery); elasticsearchTemplate.index(indexQuery);
SearchQuery query = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
.withIndices(alias2).withTypes(TYPE_NAME).build();
long count = elasticsearchTemplate.count(query, SampleEntity.class);
// then // then
Set<String> aliases = elasticsearchTemplate.queryForAlias(INDEX_NAME); List<AliasMetaData> responseAlias1 = elasticsearchTemplate.queryForAlias(INDEX_NAME_1);
assertThat(aliases, is(notNullValue())); assertThat(responseAlias1, is(notNullValue()));
assertThat(aliases.contains(alias1), is(true)); assertThat(responseAlias1.get(0).alias(), is(alias1));
assertThat(aliases.contains(alias2), is(true)); assertThat(responseAlias1.get(0).indexRouting(), is("0"));
assertThat(count, is(0L));
List<AliasMetaData> responseAlias2 = elasticsearchTemplate.queryForAlias(INDEX_NAME_2);
assertThat(responseAlias2, is(notNullValue()));
assertThat(responseAlias2.get(0).alias(), is(alias2));
assertThat(responseAlias2.get(0).searchRouting(), is("1"));
//cleanup //cleanup
elasticsearchTemplate.removeAlias(aliasQuery1); elasticsearchTemplate.removeAlias(aliasQuery1);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2014-2015 the original author or authors. * Copyright 2014-2016 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.
@ -338,6 +338,8 @@ public class ElasticsearchTemplateTests {
IndexQuery indexQuery = getIndexQuery(sampleEntity); IndexQuery indexQuery = getIndexQuery(sampleEntity);
elasticsearchTemplate.index(indexQuery); elasticsearchTemplate.index(indexQuery);
elasticsearchTemplate.refresh(SampleEntity.class, true);
// when // when
DeleteQuery deleteQuery = new DeleteQuery(); DeleteQuery deleteQuery = new DeleteQuery();
deleteQuery.setQuery(termQuery("id", documentId)); deleteQuery.setQuery(termQuery("id", documentId));

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2013-2014 the original author or authors. * Copyright 2013-2016 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.
@ -60,8 +60,8 @@ public class MappingBuilderTests {
@Test @Test
public void testInfiniteLoopAvoidance() throws IOException { public void testInfiniteLoopAvoidance() throws IOException {
final String expected = "{\"mapping\":{\"properties\":{\"message\":{\"store\":true,\"" + final String expected = "{\"mapping\":{\"properties\":{\"message\":{\"store\":true,\"" +
"type\":\"string\",\"index\":\"not_analyzed\",\"search_analyzer\":\"standard\"," + "type\":\"string\",\"index\":\"not_analyzed\"," +
"\"index_analyzer\":\"standard\"}}}}"; "\"analyzer\":\"standard\"}}}}";
XContentBuilder xContentBuilder = MappingBuilder.buildMapping(SampleTransientEntity.class, "mapping", "id", null); XContentBuilder xContentBuilder = MappingBuilder.buildMapping(SampleTransientEntity.class, "mapping", "id", null);
assertThat(xContentBuilder.string(), is(expected)); assertThat(xContentBuilder.string(), is(expected));
@ -115,8 +115,8 @@ public class MappingBuilderTests {
@Test @Test
public void shouldBuildMappingWithSuperclass() throws IOException { public void shouldBuildMappingWithSuperclass() throws IOException {
final String expected = "{\"mapping\":{\"properties\":{\"message\":{\"store\":true,\"" + final String expected = "{\"mapping\":{\"properties\":{\"message\":{\"store\":true,\"" +
"type\":\"string\",\"index\":\"not_analyzed\",\"search_analyzer\":\"standard\"," + "type\":\"string\",\"index\":\"not_analyzed\",\"analyzer\":\"standard\"}" +
"\"index_analyzer\":\"standard\"},\"createdDate\":{\"store\":false," + ",\"createdDate\":{\"store\":false," +
"\"type\":\"date\",\"index\":\"not_analyzed\"}}}}"; "\"type\":\"date\",\"index\":\"not_analyzed\"}}}}";
XContentBuilder xContentBuilder = MappingBuilder.buildMapping(SampleInheritedEntity.class, "mapping", "id", null); XContentBuilder xContentBuilder = MappingBuilder.buildMapping(SampleInheritedEntity.class, "mapping", "id", null);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2013 the original author or authors. * Copyright 2013-2016 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.
@ -146,7 +146,7 @@ public class ElasticsearchTemplateGeoTests {
List<LocationMarkerEntity> geoAuthorsForGeoCriteria = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery, LocationMarkerEntity.class); List<LocationMarkerEntity> geoAuthorsForGeoCriteria = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery, LocationMarkerEntity.class);
//then //then
assertThat(geoAuthorsForGeoCriteria.size(), is(3)); assertThat(geoAuthorsForGeoCriteria.size(), is(2));
} }
@Test @Test
@ -180,7 +180,7 @@ public class ElasticsearchTemplateGeoTests {
//given //given
loadAnnotationBaseEntities(); loadAnnotationBaseEntities();
CriteriaQuery geoLocationCriteriaQuery = new CriteriaQuery( CriteriaQuery geoLocationCriteriaQuery = new CriteriaQuery(
new Criteria("locationAsArray").within("u1044", "1km")); new Criteria("locationAsArray").within("u1044", "3km"));
//when //when
List<LocationMarkerEntity> geoAuthorsForGeoCriteria = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery, LocationMarkerEntity.class); List<LocationMarkerEntity> geoAuthorsForGeoCriteria = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery, LocationMarkerEntity.class);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2013-2014 the original author or authors. * Copyright 2013-2016 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.
@ -25,7 +25,6 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.apache.lucene.util.CollectionUtil;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;