Skip to content

Commit

Permalink
Removed search_indices parameter, which is no longer needed now that …
Browse files Browse the repository at this point in the history
…index aliases are supported.
  • Loading branch information
sjudeng committed Nov 19, 2017
1 parent 282a2d4 commit d0660ed
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 68 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 1 addition & 3 deletions gs-web-elasticsearch/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,9 @@ Available data store configuration parameters are summarized in the following ta
* - index_name
- Index name or alias
* - ssl_enabled
- Whether to enable SSL for https connections
- Whether to enable SSL (HTTPS)
* - reject_unauthorized
- Whether to verify server certificate when SSL is enabled
* - search_indices
- Indices to use when searching. Enables multi/cross index searches.
* - default_max_features
- Default used when maxFeatures is unlimited
* - source_filtering_enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ public class ElasticDataStore extends ContentDataStore {

private final String indexName;

private final String searchIndices;

private final List<Name> baseTypeNames;

private final Map<Name, String> docTypes;
Expand Down Expand Up @@ -84,21 +82,15 @@ public enum ArrayEncoding {

}

public ElasticDataStore(String searchHost, Integer hostPort, String indexName, String searchIndices) throws IOException {
this(RestClient.builder(new HttpHost(searchHost, hostPort, "http")).build(), indexName, searchIndices);
public ElasticDataStore(String searchHost, Integer hostPort, String indexName) throws IOException {
this(RestClient.builder(new HttpHost(searchHost, hostPort, "http")).build(), indexName);
}

public ElasticDataStore(RestClient restClient, String indexName, String searchIndices) throws IOException {
public ElasticDataStore(RestClient restClient, String indexName) throws IOException {
LOGGER.fine("Initializing data store for " + indexName);

this.indexName = indexName;

if (searchIndices != null) {
this.searchIndices = searchIndices;
} else {
this.searchIndices = indexName;
}

try {
final Response response = restClient.performRequest("GET", "/", Collections.<String, String>emptyMap());
if (response.getStatusLine().getStatusCode() >= 400) {
Expand Down Expand Up @@ -219,10 +211,6 @@ public String getIndexName() {
return indexName;
}

public String getSearchIndices() {
return searchIndices;
}

public ElasticClient getClient() {
return client;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ public class ElasticDataStoreFactory implements DataStoreFactorySpi {
/** Index name. **/
public static final Param INDEX_NAME = new Param("index_name", String.class, "Index defining type", true);

/** Index name. **/
public static final Param SEARCH_INDICES = new Param("search_indices", String.class, "Indices for search (default is index_name)", false);

public static final Param DEFAULT_MAX_FEATURES = new Param("default_max_features", Integer.class, "Default max features", false, 100);

public static final Param SOURCE_FILTERING_ENABLED = new Param("source_filtering_enabled", Boolean.class, "Enable source field filtering", false, false);
Expand All @@ -71,7 +68,6 @@ public class ElasticDataStoreFactory implements DataStoreFactorySpi {
SSL_ENABLED,
SSL_REJECT_UNAUTHORIZED,
INDEX_NAME,
SEARCH_INDICES,
DEFAULT_MAX_FEATURES,
SOURCE_FILTERING_ENABLED,
SCROLL_ENABLED,
Expand Down Expand Up @@ -133,7 +129,6 @@ public DataStore createDataStore(Map<String, Serializable> params) throws IOExce
final String searchHost = (String) getValue(HOSTNAME, params);
final Integer hostPort = (Integer) getValue(HOSTPORT, params);
final String indexName = (String) INDEX_NAME.lookUp(params);
final String searchIndices = (String) SEARCH_INDICES.lookUp(params);
final String arrayEncoding = (String) getValue(ARRAY_ENCODING, params);
final Boolean sslEnabled = (Boolean) getValue(SSL_ENABLED, params);
final Boolean sslRejectUnauthorized = (Boolean) getValue(SSL_REJECT_UNAUTHORIZED, params);
Expand All @@ -159,7 +154,7 @@ public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpCli
});
}

final ElasticDataStore dataStore = new ElasticDataStore(builder.build(), indexName, searchIndices);
final ElasticDataStore dataStore = new ElasticDataStore(builder.build(), indexName);
dataStore.setDefaultMaxFeatures((Integer) getValue(DEFAULT_MAX_FEATURES, params));
dataStore.setSourceFilteringEnabled((Boolean) getValue(SOURCE_FILTERING_ENABLED, params));
dataStore.setScrollEnabled((Boolean)getValue(SCROLL_ENABLED, params));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected int getCountInternal(Query query) throws IOException {
searchRequest.setSize(0);
final ElasticDataStore dataStore = getDataStore();
final String docType = dataStore.getDocType(entry.getName());
final ElasticResponse sr = dataStore.getClient().search(dataStore.getSearchIndices(), docType, searchRequest);
final ElasticResponse sr = dataStore.getClient().search(dataStore.getIndexName(), docType, searchRequest);
final int totalHits = (int) sr.getTotalNumHits();
final int size = getSize(query);
final int from = getStartIndex(query);
Expand All @@ -115,7 +115,7 @@ protected FeatureReader<SimpleFeatureType, SimpleFeature> getReaderInternal(Quer
final String docType = dataStore.getDocType(entry.getName());
final boolean scroll = !useSortOrPagination(query) && dataStore.getScrollEnabled();
final ElasticRequest searchRequest = prepareSearchRequest(query, scroll);
final ElasticResponse sr = dataStore.getClient().search(dataStore.getSearchIndices(), docType, searchRequest);
final ElasticResponse sr = dataStore.getClient().search(dataStore.getIndexName(), docType, searchRequest);
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine("Search response: " + sr);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,36 +83,6 @@ public void testFactory() throws IOException {
assertTrue(source instanceof ElasticDataStore);
}

@Test
public void testFactoryWithSearchIndices() throws IOException {
assertTrue(new ElasticDataStoreFactory().isAvailable());
scanForPlugins();

Map<String,Serializable> map = new HashMap<>();
map.put(ElasticDataStoreFactory.HOSTNAME.key, "localhost");
map.put(ElasticDataStoreFactory.HOSTPORT.key, PORT);
map.put(ElasticDataStoreFactory.INDEX_NAME.key, "sample");
map.put(ElasticDataStoreFactory.SEARCH_INDICES.key, "sample1,sample2");

Iterator<DataStoreFactorySpi> ps = getAvailableDataSources();
ElasticDataStoreFactory fac;
while (ps.hasNext()) {
fac = (ElasticDataStoreFactory) ps.next();

try {
if (fac.canProcess(map)) {
source = fac.createDataStore(map);
}
} catch (Throwable t) {
LOGGER.log(Level.WARNING, "Could not acquire " + fac.getDescription() + ":" + t, t);
}
}

assertNotNull(source);
assertTrue(source instanceof ElasticDataStore);
assertTrue(((ElasticDataStore) source).getSearchIndices().equals("sample1,sample2"));
}

@Test
public void testFactoryWithMissingRequired() throws IOException {
assertTrue(new ElasticDataStoreFactory().isAvailable());
Expand All @@ -121,7 +91,6 @@ public void testFactoryWithMissingRequired() throws IOException {
Map<String,Serializable> map = new HashMap<>();
map.put(ElasticDataStoreFactory.HOSTNAME.key, "localhost");
map.put(ElasticDataStoreFactory.HOSTPORT.key, PORT);
map.put(ElasticDataStoreFactory.SEARCH_INDICES.key, "sample1,sample2");

Iterator<DataStoreFactorySpi> ps = getAvailableDataSources();
ElasticDataStoreFactory fac;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,6 @@ public void testGetNamesByAlias() throws IOException {
assertTrue(new HashSet<String>(Arrays.asList(typeNames)).contains(("active")));
}

@Test
public void testDefaultSearchIndices() throws IOException {
Map<String,Serializable> params = createConnectionParams();

ElasticDataStoreFactory factory = new ElasticDataStoreFactory();
DataStore dataStore = factory.createDataStore(params);
String indexName = ((ElasticDataStore) dataStore).getIndexName();
String searchIndices = ((ElasticDataStore) dataStore).getSearchIndices();
assertTrue(searchIndices.equals(indexName));
}

@Test
public void testLayerConfigClone() {
ElasticLayerConfiguration layerConfig = new ElasticLayerConfiguration("d");
Expand Down

0 comments on commit d0660ed

Please sign in to comment.