Skip to content

Commit

Permalink
Upgrade to ES 1.3.0. Closes #48
Browse files Browse the repository at this point in the history
All api tests pass.
  • Loading branch information
lukas-vlcek committed Sep 16, 2014
1 parent c410ec6 commit b4a49b0
Show file tree
Hide file tree
Showing 16 changed files with 100 additions and 79 deletions.
22 changes: 0 additions & 22 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,31 +149,11 @@
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>${org.elasticsearch.version}</version>
<exclusions>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.jboss.elasticsearch</groupId>
<artifactId>structured-content-tools</artifactId>
<version>${structured-content-tools.version}</version>
</dependency>

<!-- Needed for JSON parsing. Version is taken from EAP BOMs -->
Expand Down Expand Up @@ -215,13 +195,11 @@
<dependency>
<groupId>org.jboss.elasticsearch</groupId>
<artifactId>elasticsearch-river-jira</artifactId>
<version>${elasticsearch-river-jira.version}</version>
<!-- re-enabled commons-logging otherwise httpclient doesn't work -->
</dependency>
<dependency>
<groupId>org.jboss.elasticsearch</groupId>
<artifactId>elasticsearch-river-remote</artifactId>
<version>${elasticsearch-river-remote.version}</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void performTask() throws Exception {
for (String esField : esFields) {
searchFilters.add(new TermsFilterBuilder(esField, esValues));
}
srb.setFilter(new OrFilterBuilder(searchFilters.toArray(new FilterBuilder[searchFilters.size()])));
srb.setPostFilter(new OrFilterBuilder(searchFilters.toArray(new FilterBuilder[searchFilters.size()])));
srb.setScroll(new TimeValue(ES_SCROLL_KEEPALIVE)).setSearchType(SearchType.SCAN);

SearchResponse scrollResp = srb.execute().actionGet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected RenormalizeByEsValueTask() {

@Override
protected void addFilters(SearchRequestBuilder srb) {
srb.setFilter(new TermsFilterBuilder(esField, esValues));
srb.setPostFilter(new TermsFilterBuilder(esField, esValues));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -423,13 +423,13 @@ public Object deleteContent(@PathParam("type") String type, @PathParam("contentI
DeleteResponse dr = searchClientService.getClient().prepareDelete(indexName, indexType, sysContentId).execute()
.actionGet();

if (!dr.isNotFound()) {
if (dr.isFound()) {
ContentDeletedEvent event = new ContentDeletedEvent(sysContentId);
log.log(Level.FINE, "Going to fire event {0}", event);
eventContentDeleted.fire(event);
}

if (dr.isNotFound() && !Boolean.parseBoolean(ignoreMissing)) {
if (!dr.isFound() && !Boolean.parseBoolean(ignoreMissing)) {
return Response.status(Status.NOT_FOUND).entity("Content not found to be deleted.").build();
} else {
return Response.ok("Content deleted successfully.").build();
Expand Down Expand Up @@ -490,7 +490,7 @@ public Object deleteContentBulk(@PathParam("type") String type, @AuditContent Ma
String contentId = ids.get(i);
if (!bri.isFailed()) {
DeleteResponse dr = bri.getResponse();
if (!dr.isNotFound()) {
if (dr.isFound()) {
ContentDeletedEvent event = new ContentDeletedEvent(sysIds.get(i));
log.log(Level.FINE, "Going to fire event {0}", event);
eventContentDeleted.fire(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;

import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.admin.indices.flush.FlushRequest;
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
import org.elasticsearch.action.delete.DeleteResponse;
Expand Down Expand Up @@ -84,7 +84,7 @@ public SearchResponse performFilterByOneField(String indexName, String indexType
try {
SearchRequestBuilder searchBuilder = getClient().prepareSearch(indexName).setTypes(indexType).setSize(10);

searchBuilder.setFilter(FilterBuilders.queryFilter(QueryBuilders.matchQuery(fieldName, fieldValue)));
searchBuilder.setPostFilter(FilterBuilders.queryFilter(QueryBuilders.matchQuery(fieldName, fieldValue)));
searchBuilder.setQuery(QueryBuilders.matchAllQuery());

final SearchResponse response = searchBuilder.execute().actionGet();
Expand Down Expand Up @@ -114,7 +114,7 @@ public SearchResponse performQueryByOneFieldAnyValue(String indexName, String in
SearchRequestBuilder searchBuilder = getClient().prepareSearch(indexName).setTypes(indexType)
.setScroll(new TimeValue(ES_SCROLL_KEEPALIVE)).setSearchType(SearchType.SCAN).setSize(10);

searchBuilder.setFilter(FilterBuilders.notFilter(FilterBuilders.missingFilter(fieldName)));
searchBuilder.setPostFilter(FilterBuilders.notFilter(FilterBuilders.missingFilter(fieldName)));
searchBuilder.setQuery(QueryBuilders.matchAllQuery());
searchBuilder.addSort(sortByField, SortOrder.ASC);
final SearchResponse response = searchBuilder.execute().actionGet();
Expand All @@ -138,7 +138,7 @@ public SearchResponse executeESScrollSearchNextRequest(SearchResponse scrollResp
* @param id of document to get
* @return ES get response
* @throws SearchIndexMissingException
* @throws ElasticSearchException if something is wrong
* @throws ElasticsearchException if something is wrong
*/
public GetResponse performGet(String indexName, String indexType, String id) throws SearchIndexMissingException {
try {
Expand Down Expand Up @@ -168,7 +168,7 @@ public void performPutAsync(String indexName, String indexType, String id, Map<S
* @param indexType type of ES document to put
* @param content of document to put
* @return ES response object
* @throws ElasticSearchException if something is wrong
* @throws ElasticsearchException if something is wrong
*/
public IndexResponse performPut(String indexName, String indexType, Map<String, Object> content) {
return getClient().prepareIndex(indexName, indexType).setSource(content).execute().actionGet();
Expand All @@ -182,7 +182,7 @@ public IndexResponse performPut(String indexName, String indexType, Map<String,
* @param id of ES document to put
* @param content of document to put
* @return ES response object
* @throws ElasticSearchException if something is wrong
* @throws ElasticsearchException if something is wrong
*/
public IndexResponse performPut(String indexName, String indexType, String id, Map<String, Object> content) {
return getClient().prepareIndex(indexName, indexType, id).setSource(content).execute().actionGet();
Expand All @@ -196,7 +196,7 @@ public IndexResponse performPut(String indexName, String indexType, String id, M
* @param id of document to delete
* @return {@link DeleteResponse}
* @throws SearchIndexMissingException
* @throws ElasticSearchException if something is wrong
* @throws ElasticsearchException if something is wrong
*/
public DeleteResponse performDelete(String indexName, String indexType, String id) throws SearchIndexMissingException {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import javax.inject.Inject;
import javax.inject.Named;

import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.settings.SettingsException;
Expand Down Expand Up @@ -103,7 +103,7 @@ public SearchResponse performSearch(QuerySettings querySettings, String response
statsClientService.writeStatisticsRecord(statsRecordType, responseUuid, searchResponse,
System.currentTimeMillis(), querySettings);
return searchResponse;
} catch (ElasticSearchException e) {
} catch (ElasticsearchException e) {
statsClientService.writeStatisticsRecord(statsRecordType, e, System.currentTimeMillis(), querySettings);
throw e;
}
Expand All @@ -123,7 +123,7 @@ protected SearchRequestBuilder performSearchInternal(final QuerySettings querySe
try {
parsedFilterConfigService.prepareFiltersForRequest(querySettings.getFilters());
} catch (ReflectiveOperationException e) {
throw new ElasticSearchException("Can not prepare filters", e);
throw new ElasticsearchException("Can not prepare filters", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
Expand Down Expand Up @@ -186,7 +186,7 @@ public SearchResponse performSearch(
* @param dateInMillis timestamp when search was performed
* @param querySettings client query settings
*/
public void writeStatisticsRecord(StatsRecordType type, ElasticSearchException ex, long dateInMillis,
public void writeStatisticsRecord(StatsRecordType type, ElasticsearchException ex, long dateInMillis,
QuerySettings querySettings) {

if (!statsConfiguration.enabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.elasticsearch.action.search.MultiSearchRequest;
import org.elasticsearch.action.search.MultiSearchRequestBuilder;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.client.Client;
import org.json.JSONException;
import org.junit.Assert;
import org.junit.Test;
Expand All @@ -30,15 +31,16 @@ public class SuggestionsRestServiceTest {
@Test
public void handleSuggestionsProject() throws IOException, JSONException {
SuggestionsRestService tested = new SuggestionsRestService();
Client client = Mockito.mock(Client.class);
tested.searchClientService = Mockito.mock(SearchClientService.class);
tested.log = Logger.getLogger("testlogger");

SearchRequestBuilder srbMock = new SearchRequestBuilder(null);
SearchRequestBuilder srbMock = new SearchRequestBuilder(client);
srbMock = tested.getProjectSearchNGramRequestBuilder(srbMock, "JBoss", 5, null);

TestUtils.assertJsonContentFromClasspathFile("/suggestions/project_suggestions_ngram.json", srbMock.toString());

srbMock = new SearchRequestBuilder(null);
srbMock = new SearchRequestBuilder(client);
List<String> customFields = new ArrayList<>();
customFields.add("archived");
customFields.add("license");
Expand All @@ -47,12 +49,12 @@ public void handleSuggestionsProject() throws IOException, JSONException {

TestUtils.assertJsonContentFromClasspathFile("/suggestions/project_suggestions_ngram_with_custom_fields.json", srbMock.toString());

srbMock = new SearchRequestBuilder(null);
srbMock = new SearchRequestBuilder(client);
srbMock = tested.getProjectSearchFuzzyRequestBuilder(srbMock, "JBoss", 5, null);

TestUtils.assertJsonContentFromClasspathFile("/suggestions/project_suggestions_fuzzy.json", srbMock.toString());

srbMock = new SearchRequestBuilder(null);
srbMock = new SearchRequestBuilder(client);
customFields = new ArrayList<>();
customFields.add("archived");
customFields.add("license");
Expand All @@ -65,12 +67,13 @@ public void handleSuggestionsProject() throws IOException, JSONException {
@Test
public void testMultiSearchRequestBuilder() throws IOException {
SuggestionsRestService tested = new SuggestionsRestService();
Client client = Mockito.mock(Client.class);
tested.searchClientService = Mockito.mock(SearchClientService.class);
tested.log = Logger.getLogger("testlogger");

MultiSearchRequestBuilder msrb = new MultiSearchRequestBuilder(null);
SearchRequestBuilder srbNGram = new SearchRequestBuilder(null);
SearchRequestBuilder srbFuzzy = new SearchRequestBuilder(null);
MultiSearchRequestBuilder msrb = new MultiSearchRequestBuilder(client);
SearchRequestBuilder srbNGram = new SearchRequestBuilder(client);
SearchRequestBuilder srbFuzzy = new SearchRequestBuilder(client);

msrb = tested.getProjectMultiSearchRequestBuilder(msrb,
tested.getProjectSearchNGramRequestBuilder(srbNGram, "JBoss", 5, null),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.Map;
import java.util.logging.Logger;

import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.Client;
import org.junit.Assert;
Expand Down Expand Up @@ -377,7 +377,7 @@ private ContributorProfileService getTested(Client client) {
return ret;
}

private void initIndex(Client client) throws ElasticSearchException, IOException {
private void initIndex(Client client) throws ElasticsearchException, IOException {
client.admin().indices().prepareCreate(ContributorProfileService.SEARCH_INDEX_NAME).execute().actionGet();
client
.admin()
Expand Down

0 comments on commit b4a49b0

Please sign in to comment.