review comment fixes

This commit is contained in:
Colin Goodheart-Smithe 2015-10-05 13:27:14 +01:00
parent 117d8d2606
commit 7fbd565c5c
11 changed files with 45 additions and 89 deletions

View File

@ -25,7 +25,6 @@ import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.warmer.IndexWarmersMetaData; import org.elasticsearch.search.warmer.IndexWarmersMetaData;
import java.io.IOException; import java.io.IOException;
@ -69,7 +68,10 @@ public class GetWarmersResponse extends ActionResponse {
for (int j = 0; j < valueSize; j++) { for (int j = 0; j < valueSize; j++) {
String name = in.readString(); String name = in.readString();
String[] types = in.readStringArray(); String[] types = in.readStringArray();
IndexWarmersMetaData.SearchSource source = new IndexWarmersMetaData.SearchSource(in); IndexWarmersMetaData.SearchSource source = null;
if (in.readBoolean()) {
source = new IndexWarmersMetaData.SearchSource(in);
}
Boolean queryCache = null; Boolean queryCache = null;
queryCache = in.readOptionalBoolean(); queryCache = in.readOptionalBoolean();
warmerEntryBuilder.add(new IndexWarmersMetaData.Entry( warmerEntryBuilder.add(new IndexWarmersMetaData.Entry(
@ -94,7 +96,11 @@ public class GetWarmersResponse extends ActionResponse {
for (IndexWarmersMetaData.Entry warmerEntry : indexEntry.value) { for (IndexWarmersMetaData.Entry warmerEntry : indexEntry.value) {
out.writeString(warmerEntry.name()); out.writeString(warmerEntry.name());
out.writeStringArray(warmerEntry.types()); out.writeStringArray(warmerEntry.types());
boolean hasWarmerSource = warmerEntry != null;
out.writeBoolean(hasWarmerSource);
if (hasWarmerSource) {
warmerEntry.source().writeTo(out); warmerEntry.source().writeTo(out);
}
out.writeOptionalBoolean(warmerEntry.requestCache()); out.writeOptionalBoolean(warmerEntry.requestCache());
} }
} }

View File

@ -19,26 +19,18 @@
package org.elasticsearch.action.count; package org.elasticsearch.action.count;
import org.elasticsearch.ElasticsearchGenerationException;
import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.support.QuerySourceBuilder;
import org.elasticsearch.action.support.broadcast.BroadcastRequest; import org.elasticsearch.action.support.broadcast.BroadcastRequest;
import org.elasticsearch.client.Requests;
import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.builder.SearchSourceBuilder;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Map;
import static org.elasticsearch.search.internal.SearchContext.DEFAULT_TERMINATE_AFTER; import static org.elasticsearch.search.internal.SearchContext.DEFAULT_TERMINATE_AFTER;
@ -66,7 +58,7 @@ public class CountRequest extends BroadcastRequest<CountRequest> {
private int terminateAfter = DEFAULT_TERMINATE_AFTER; private int terminateAfter = DEFAULT_TERMINATE_AFTER;
private SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); private QueryBuilder<?> queryBuilder = null;
/** /**
* Constructs a new count request against the provided indices. No indices provided means it will * Constructs a new count request against the provided indices. No indices provided means it will
@ -96,13 +88,8 @@ public class CountRequest extends BroadcastRequest<CountRequest> {
/** /**
* The query to execute * The query to execute
*/ */
public CountRequest query(QueryBuilder queryBuilder) { public CountRequest query(QueryBuilder<?> queryBuilder) {
this.searchSourceBuilder = new SearchSourceBuilder().query(queryBuilder); this.queryBuilder = queryBuilder;
return this;
}
public CountRequest searchSource(SearchSourceBuilder searchSourceBuilder) {
this.searchSourceBuilder = searchSourceBuilder;
return this; return this;
} }
@ -184,7 +171,7 @@ public class CountRequest extends BroadcastRequest<CountRequest> {
public String toString() { public String toString() {
String sSource = "_na_"; String sSource = "_na_";
try { try {
sSource = XContentHelper.toString(searchSourceBuilder); sSource = XContentHelper.toString(queryBuilder);
} catch (Exception e) { } catch (Exception e) {
// ignore // ignore
} }
@ -192,6 +179,8 @@ public class CountRequest extends BroadcastRequest<CountRequest> {
} }
public SearchRequest toSearchRequest() { public SearchRequest toSearchRequest() {
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(queryBuilder);
searchSourceBuilder.size(0); searchSourceBuilder.size(0);
if (minScore() != DEFAULT_MIN_SCORE) { if (minScore() != DEFAULT_MIN_SCORE) {
searchSourceBuilder.minScore(minScore()); searchSourceBuilder.minScore(minScore());
@ -207,8 +196,4 @@ public class CountRequest extends BroadcastRequest<CountRequest> {
searchRequest.preference(preference()); searchRequest.preference(preference());
return searchRequest; return searchRequest;
} }
SearchSourceBuilder sourceBuilder() {
return searchSourceBuilder;
}
} }

View File

@ -19,7 +19,6 @@
package org.elasticsearch.action.count; package org.elasticsearch.action.count;
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.search.SearchAction; import org.elasticsearch.action.search.SearchAction;
import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchResponse;
@ -27,11 +26,7 @@ import org.elasticsearch.action.support.DelegatingActionListener;
import org.elasticsearch.action.support.QuerySourceBuilder; import org.elasticsearch.action.support.QuerySourceBuilder;
import org.elasticsearch.action.support.broadcast.BroadcastOperationRequestBuilder; import org.elasticsearch.action.support.broadcast.BroadcastOperationRequestBuilder;
import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.search.builder.SearchSourceBuilder;
/** /**
* A count action request builder. * A count action request builder.
@ -86,14 +81,6 @@ public class CountRequestBuilder extends BroadcastOperationRequestBuilder<CountR
return this; return this;
} }
/**
* The source to execute.
*/
public CountRequestBuilder setSource(SearchSourceBuilder source) {
request().searchSource(source);
return this;
}
/** /**
* The query source to execute. * The query source to execute.
*/ */
@ -120,8 +107,8 @@ public class CountRequestBuilder extends BroadcastOperationRequestBuilder<CountR
@Override @Override
public String toString() { public String toString() {
if (request.sourceBuilder() != null) { if (request != null) {
return request.sourceBuilder().toString(); return request.toString();
} }
return new QuerySourceBuilder().toString(); return new QuerySourceBuilder().toString();
} }

View File

@ -102,7 +102,10 @@ public class DfsOnlyRequest extends BroadcastRequest<DfsOnlyRequest> {
@Override @Override
public String toString() { public String toString() {
String sSource = searchRequest.source().toString(); String sSource = "_na_";
if (searchRequest.source() != null) {
sSource = searchRequest.source().toString();
}
return "[" + Arrays.toString(indices) + "]" + Arrays.toString(types()) + ", source[" + sSource + "]"; return "[" + Arrays.toString(indices) + "]" + Arrays.toString(types()) + ", source[" + sSource + "]";
} }

View File

@ -21,7 +21,6 @@ package org.elasticsearch.cluster.metadata;
import com.carrotsearch.hppc.cursors.ObjectCursor; import com.carrotsearch.hppc.cursors.ObjectCursor;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.cluster.Diff; import org.elasticsearch.cluster.Diff;
@ -41,11 +40,7 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.loader.SettingsLoader; import org.elasticsearch.common.settings.loader.SettingsLoader;
import org.elasticsearch.common.xcontent.FromXContentBuilder; import org.elasticsearch.common.xcontent.*;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.search.warmer.IndexWarmersMetaData; import org.elasticsearch.search.warmer.IndexWarmersMetaData;
@ -61,9 +56,7 @@ import java.util.Map;
import static org.elasticsearch.cluster.node.DiscoveryNodeFilters.OpType.AND; import static org.elasticsearch.cluster.node.DiscoveryNodeFilters.OpType.AND;
import static org.elasticsearch.cluster.node.DiscoveryNodeFilters.OpType.OR; import static org.elasticsearch.cluster.node.DiscoveryNodeFilters.OpType.OR;
import static org.elasticsearch.common.settings.Settings.readSettingsFromStream; import static org.elasticsearch.common.settings.Settings.*;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.elasticsearch.common.settings.Settings.writeSettingsToStream;
/** /**
* *
@ -531,8 +524,7 @@ public class IndexMetaData implements Diffable<IndexMetaData>, FromXContentBuild
} }
@Override @Override
public IndexMetaData fromXContent(XContentParser parser, ParseFieldMatcher parseFieldMatcher) public IndexMetaData fromXContent(XContentParser parser, ParseFieldMatcher parseFieldMatcher) throws IOException {
throws IOException {
return Builder.fromXContent(parser); return Builder.fromXContent(parser);
} }

View File

@ -26,9 +26,6 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.indices.query.IndicesQueriesRegistry; import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestChannel; import org.elasticsearch.rest.RestChannel;
@ -75,10 +72,7 @@ public class RestPutWarmerAction extends BaseRestHandler {
PutWarmerRequest putWarmerRequest = new PutWarmerRequest(request.param("name")); PutWarmerRequest putWarmerRequest = new PutWarmerRequest(request.param("name"));
BytesReference sourceBytes = RestActions.getRestContent(request); BytesReference sourceBytes = RestActions.getRestContent(request);
XContentParser parser = XContentFactory.xContent(sourceBytes).createParser(sourceBytes); SearchSourceBuilder source = RestActions.getRestSearchSource(sourceBytes, queryRegistry);
QueryParseContext queryParseContext = new QueryParseContext(queryRegistry);
queryParseContext.reset(parser);
SearchSourceBuilder source = SearchSourceBuilder.PROTOTYPE.fromXContent(parser, queryParseContext);
SearchRequest searchRequest = new SearchRequest(Strings.splitStringByCommaToArray(request.param("index"))) SearchRequest searchRequest = new SearchRequest(Strings.splitStringByCommaToArray(request.param("index")))
.types(Strings.splitStringByCommaToArray(request.param("type"))) .types(Strings.splitStringByCommaToArray(request.param("type")))
.requestCache(request.paramAsBoolean("request_cache", null)).source(source); .requestCache(request.paramAsBoolean("request_cache", null)).source(source);

View File

@ -23,7 +23,6 @@ import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.count.CountRequest; import org.elasticsearch.action.count.CountRequest;
import org.elasticsearch.action.count.CountResponse; import org.elasticsearch.action.count.CountResponse;
import org.elasticsearch.action.support.QuerySourceBuilder; import org.elasticsearch.action.support.QuerySourceBuilder;
import org.elasticsearch.bootstrap.Elasticsearch;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.Table; import org.elasticsearch.common.Table;
@ -38,11 +37,9 @@ import org.elasticsearch.rest.RestChannel;
import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestResponse;
import org.elasticsearch.rest.action.search.RestSearchAction;
import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestActions;
import org.elasticsearch.rest.action.support.RestResponseListener; import org.elasticsearch.rest.action.support.RestResponseListener;
import org.elasticsearch.rest.action.support.RestTable; import org.elasticsearch.rest.action.support.RestTable;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter; import org.joda.time.format.DateTimeFormatter;
@ -78,8 +75,8 @@ public class RestCountAction extends AbstractCatAction {
try (XContentParser requestParser = XContentFactory.xContent(source).createParser(source)) { try (XContentParser requestParser = XContentFactory.xContent(source).createParser(source)) {
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry); QueryParseContext context = new QueryParseContext(indicesQueriesRegistry);
context.reset(requestParser); context.reset(requestParser);
final SearchSourceBuilder builder = SearchSourceBuilder.PROTOTYPE.fromXContent(requestParser, context); final QueryBuilder<?> builder = context.parseInnerQueryBuilder();
countRequest.searchSource(builder); countRequest.query(builder);
} catch (IOException e) { } catch (IOException e) {
throw new ElasticsearchException("failed to parse source", e); throw new ElasticsearchException("failed to parse source", e);
} }

View File

@ -23,7 +23,6 @@ import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.count.CountRequest; import org.elasticsearch.action.count.CountRequest;
import org.elasticsearch.action.count.CountResponse; import org.elasticsearch.action.count.CountResponse;
import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.QuerySourceBuilder;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
@ -43,7 +42,6 @@ import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestResponse;
import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestActions;
import org.elasticsearch.rest.action.support.RestBuilderListener; import org.elasticsearch.rest.action.support.RestBuilderListener;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import java.io.IOException; import java.io.IOException;
@ -81,8 +79,8 @@ public class RestCountAction extends BaseRestHandler {
try (XContentParser requestParser = XContentFactory.xContent(restContent).createParser(restContent)) { try (XContentParser requestParser = XContentFactory.xContent(restContent).createParser(restContent)) {
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry); QueryParseContext context = new QueryParseContext(indicesQueriesRegistry);
context.reset(requestParser); context.reset(requestParser);
final SearchSourceBuilder builder = SearchSourceBuilder.PROTOTYPE.fromXContent(requestParser, context); final QueryBuilder<?> builder = context.parseInnerQueryBuilder();
countRequest.searchSource(builder); countRequest.query(builder);
} catch (IOException e) { } catch (IOException e) {
throw new ElasticsearchException("failed to parse source", e); throw new ElasticsearchException("failed to parse source", e);
} }

View File

@ -115,10 +115,7 @@ public class RestSearchAction extends BaseRestHandler {
} }
builder = null; builder = null;
} else { } else {
try (XContentParser requestParser = XContentFactory.xContent(restContent).createParser(restContent)) { builder = RestActions.getRestSearchSource(restContent, indicesQueriesRegistry);
context.reset(requestParser);
builder = SearchSourceBuilder.PROTOTYPE.fromXContent(requestParser, context);
}
} }
} else { } else {
builder = null; builder = null;

View File

@ -29,12 +29,16 @@ import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.common.xcontent.XContentBuilderString;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.Operator; import org.elasticsearch.index.query.Operator;
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.index.query.QueryParseContext;
import org.elasticsearch.index.query.QueryStringQueryBuilder; import org.elasticsearch.index.query.QueryStringQueryBuilder;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import java.io.IOException; import java.io.IOException;
@ -107,6 +111,15 @@ public class RestActions {
return queryBuilder; return queryBuilder;
} }
public static SearchSourceBuilder getRestSearchSource(BytesReference sourceBytes, IndicesQueriesRegistry queryRegistry)
throws IOException {
XContentParser parser = XContentFactory.xContent(sourceBytes).createParser(sourceBytes);
QueryParseContext queryParseContext = new QueryParseContext(queryRegistry);
queryParseContext.reset(parser);
SearchSourceBuilder source = SearchSourceBuilder.PROTOTYPE.fromXContent(parser, queryParseContext);
return source;
}
/** /**
* Get Rest content from either payload or source parameter * Get Rest content from either payload or source parameter
* @param request Rest request * @param request Rest request

View File

@ -22,23 +22,14 @@ package org.elasticsearch.action.count;
import org.elasticsearch.action.support.QuerySourceBuilder; import org.elasticsearch.action.support.QuerySourceBuilder;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.MatchAllQueryBuilder; import org.elasticsearch.index.query.MatchAllQueryBuilder;
import org.elasticsearch.index.query.MatchQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import java.io.IOException;
import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.equalTo;
@ -81,11 +72,4 @@ public class CountRequestBuilderTests extends ESTestCase {
countRequestBuilder.setQuery(new MatchAllQueryBuilder()); countRequestBuilder.setQuery(new MatchAllQueryBuilder());
assertThat(countRequestBuilder.toString(), containsString("match_all")); assertThat(countRequestBuilder.toString(), containsString("match_all"));
} }
@Test
public void testStringSourceToString() {
CountRequestBuilder countRequestBuilder = client.prepareCount();
countRequestBuilder.setSource(new SearchSourceBuilder().query(new MatchAllQueryBuilder()));
assertThat(countRequestBuilder.toString(), containsString("match_all"));
}
} }