Merge branch 'merge/named_writeable' into feature/query-refactoring
This commit is contained in:
commit
d79faab0f5
|
@ -44,9 +44,9 @@ public abstract class CompressedStreamInput extends StreamInput {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StreamInput setVersion(Version version) {
|
public void setVersion(Version version) {
|
||||||
in.setVersion(version);
|
in.setVersion(version);
|
||||||
return super.setVersion(version);
|
super.setVersion(version);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -19,17 +19,18 @@
|
||||||
|
|
||||||
package org.elasticsearch.common.io.stream;
|
package org.elasticsearch.common.io.stream;
|
||||||
|
|
||||||
|
import org.elasticsearch.Version;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps a {@link StreamInput} and associates it with a {@link NamedWriteableRegistry}
|
* Wraps a {@link StreamInput} and delegates to it. To be used to add functionality to an existing stream by subclassing.
|
||||||
*/
|
*/
|
||||||
public class FilterStreamInput extends StreamInput {
|
public abstract class FilterStreamInput extends StreamInput {
|
||||||
|
|
||||||
private final StreamInput delegate;
|
private final StreamInput delegate;
|
||||||
|
|
||||||
public FilterStreamInput(StreamInput delegate, NamedWriteableRegistry namedWriteableRegistry) {
|
protected FilterStreamInput(StreamInput delegate) {
|
||||||
super(namedWriteableRegistry);
|
|
||||||
this.delegate = delegate;
|
this.delegate = delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,4 +58,14 @@ public class FilterStreamInput extends StreamInput {
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
delegate.close();
|
delegate.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Version getVersion() {
|
||||||
|
return delegate.getVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setVersion(Version version) {
|
||||||
|
delegate.setVersion(version);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,5 +29,5 @@ public interface NamedWriteable<T> extends Writeable<T> {
|
||||||
/**
|
/**
|
||||||
* Returns the name of the writeable object
|
* Returns the name of the writeable object
|
||||||
*/
|
*/
|
||||||
String getName();
|
String getWriteableName();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
* Licensed to Elasticsearch under one or more contributor
|
||||||
|
* license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright
|
||||||
|
* ownership. Elasticsearch licenses this file to you under
|
||||||
|
* the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
* not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.elasticsearch.common.io.stream;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wraps a {@link StreamInput} and associates it with a {@link NamedWriteableRegistry}
|
||||||
|
*/
|
||||||
|
public class NamedWriteableAwareStreamInput extends FilterStreamInput {
|
||||||
|
|
||||||
|
private final NamedWriteableRegistry namedWriteableRegistry;
|
||||||
|
|
||||||
|
public NamedWriteableAwareStreamInput(StreamInput delegate, NamedWriteableRegistry namedWriteableRegistry) {
|
||||||
|
super(delegate);
|
||||||
|
this.namedWriteableRegistry = namedWriteableRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
<C> C readNamedWriteable(Class<C> categoryClass) throws IOException {
|
||||||
|
String name = readString();
|
||||||
|
NamedWriteable<? extends C> namedWriteable = namedWriteableRegistry.getPrototype(categoryClass, name);
|
||||||
|
return namedWriteable.readFrom(this);
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,28 +28,57 @@ import java.util.Map;
|
||||||
*/
|
*/
|
||||||
public class NamedWriteableRegistry {
|
public class NamedWriteableRegistry {
|
||||||
|
|
||||||
private Map<String, NamedWriteable> registry = new HashMap<>();
|
private final Map<Class<?>, InnerRegistry<?>> registry = new HashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a {@link NamedWriteable} prototype
|
* Registers a {@link NamedWriteable} prototype given its category
|
||||||
*/
|
*/
|
||||||
public synchronized void registerPrototype(NamedWriteable<?> namedWriteable) {
|
public synchronized <T> void registerPrototype(Class<T> categoryClass, NamedWriteable<? extends T> namedWriteable) {
|
||||||
if (registry.containsKey(namedWriteable.getName())) {
|
@SuppressWarnings("unchecked")
|
||||||
throw new IllegalArgumentException("named writeable of type [" + namedWriteable.getClass().getName() + "] with name [" + namedWriteable.getName() + "] " +
|
InnerRegistry<T> innerRegistry = (InnerRegistry<T>)registry.get(categoryClass);
|
||||||
"is already registered by type [" + registry.get(namedWriteable.getName()).getClass().getName() + "]");
|
if (innerRegistry == null) {
|
||||||
|
innerRegistry = new InnerRegistry<>(categoryClass);
|
||||||
|
registry.put(categoryClass, innerRegistry);
|
||||||
}
|
}
|
||||||
registry.put(namedWriteable.getName(), namedWriteable);
|
innerRegistry.registerPrototype(namedWriteable);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a prototype of the {@link NamedWriteable} object identified by the name provided as argument
|
* Returns a prototype of the {@link NamedWriteable} object identified by the name provided as argument and its category
|
||||||
*/
|
*/
|
||||||
public <C> NamedWriteable<C> getPrototype(String name) {
|
public synchronized <T> NamedWriteable<? extends T> getPrototype(Class<T> categoryClass, String name) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
NamedWriteable<C> namedWriteable = (NamedWriteable<C>)registry.get(name);
|
InnerRegistry<T> innerRegistry = (InnerRegistry<T>)registry.get(categoryClass);
|
||||||
if (namedWriteable == null) {
|
if (innerRegistry == null) {
|
||||||
throw new IllegalArgumentException("unknown named writeable with name [" + name + "]");
|
throw new IllegalArgumentException("unknown named writeable category [" + categoryClass.getName() + "]");
|
||||||
|
}
|
||||||
|
return innerRegistry.getPrototype(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class InnerRegistry<T> {
|
||||||
|
|
||||||
|
private final Map<String, NamedWriteable<? extends T>> registry = new HashMap<>();
|
||||||
|
private final Class<T> categoryClass;
|
||||||
|
|
||||||
|
private InnerRegistry(Class<T> categoryClass) {
|
||||||
|
this.categoryClass = categoryClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerPrototype(NamedWriteable<? extends T> namedWriteable) {
|
||||||
|
NamedWriteable<? extends T> existingNamedWriteable = registry.get(namedWriteable.getWriteableName());
|
||||||
|
if (existingNamedWriteable != null) {
|
||||||
|
throw new IllegalArgumentException("named writeable of type [" + namedWriteable.getClass().getName() + "] with name [" + namedWriteable.getWriteableName() + "] " +
|
||||||
|
"is already registered by type [" + existingNamedWriteable.getClass().getName() + "] within category [" + categoryClass.getName() + "]");
|
||||||
|
}
|
||||||
|
registry.put(namedWriteable.getWriteableName(), namedWriteable);
|
||||||
|
}
|
||||||
|
|
||||||
|
private NamedWriteable<? extends T> getPrototype(String name) {
|
||||||
|
NamedWriteable<? extends T> namedWriteable = registry.get(name);
|
||||||
|
if (namedWriteable == null) {
|
||||||
|
throw new IllegalArgumentException("unknown named writeable with name [" + name + "] within category [" + categoryClass.getName() + "]");
|
||||||
|
}
|
||||||
|
return namedWriteable;
|
||||||
}
|
}
|
||||||
return namedWriteable;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,6 @@
|
||||||
|
|
||||||
package org.elasticsearch.common.io.stream;
|
package org.elasticsearch.common.io.stream;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonLocation;
|
|
||||||
import com.fasterxml.jackson.core.JsonParseException;
|
|
||||||
import org.apache.lucene.index.CorruptIndexException;
|
import org.apache.lucene.index.CorruptIndexException;
|
||||||
import org.apache.lucene.index.IndexFormatTooNewException;
|
import org.apache.lucene.index.IndexFormatTooNewException;
|
||||||
import org.apache.lucene.index.IndexFormatTooOldException;
|
import org.apache.lucene.index.IndexFormatTooOldException;
|
||||||
|
@ -28,7 +26,6 @@ import org.apache.lucene.store.AlreadyClosedException;
|
||||||
import org.apache.lucene.store.LockObtainFailedException;
|
import org.apache.lucene.store.LockObtainFailedException;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
import org.apache.lucene.util.CharsRefBuilder;
|
import org.apache.lucene.util.CharsRefBuilder;
|
||||||
import org.elasticsearch.ElasticsearchException;
|
|
||||||
import org.elasticsearch.Version;
|
import org.elasticsearch.Version;
|
||||||
import org.elasticsearch.common.Nullable;
|
import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
|
@ -36,20 +33,17 @@ import org.elasticsearch.common.bytes.BytesArray;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
import org.elasticsearch.common.text.StringAndBytesText;
|
import org.elasticsearch.common.text.StringAndBytesText;
|
||||||
import org.elasticsearch.common.text.Text;
|
import org.elasticsearch.common.text.Text;
|
||||||
|
import org.elasticsearch.index.query.QueryBuilder;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.DateTimeZone;
|
import org.joda.time.DateTimeZone;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.file.NoSuchFileException;
|
import java.nio.file.NoSuchFileException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import static org.elasticsearch.ElasticsearchException.readException;
|
import static org.elasticsearch.ElasticsearchException.readException;
|
||||||
import static org.elasticsearch.ElasticsearchException.readStackTrace;
|
import static org.elasticsearch.ElasticsearchException.readStackTrace;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public abstract class StreamInput extends InputStream {
|
public abstract class StreamInput extends InputStream {
|
||||||
|
|
||||||
private final NamedWriteableRegistry namedWriteableRegistry;
|
private final NamedWriteableRegistry namedWriteableRegistry;
|
||||||
|
@ -68,9 +62,8 @@ public abstract class StreamInput extends InputStream {
|
||||||
return this.version;
|
return this.version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StreamInput setVersion(Version version) {
|
public void setVersion(Version version) {
|
||||||
this.version = version;
|
this.version = version;
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -570,25 +563,18 @@ public abstract class StreamInput extends InputStream {
|
||||||
/**
|
/**
|
||||||
* Reads a {@link NamedWriteable} from the current stream, by first reading its name and then looking for
|
* Reads a {@link NamedWriteable} from the current stream, by first reading its name and then looking for
|
||||||
* the corresponding entry in the registry by name, so that the proper object can be read and returned.
|
* the corresponding entry in the registry by name, so that the proper object can be read and returned.
|
||||||
|
* Default implementation throws {@link UnsupportedOperationException} as StreamInput doesn't hold a registry.
|
||||||
|
* Use {@link FilterInputStream} instead which wraps a stream and supports a {@link NamedWriteableRegistry} too.
|
||||||
*/
|
*/
|
||||||
public <C> C readNamedWriteable() throws IOException {
|
<C> C readNamedWriteable(@SuppressWarnings("unused") Class<C> categoryClass) throws IOException {
|
||||||
String name = readString();
|
throw new UnsupportedOperationException();
|
||||||
NamedWriteable<C> namedWriteable = namedWriteableRegistry.getPrototype(name);
|
|
||||||
return namedWriteable.readFrom(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads a list of {@link NamedWriteable} from the current stream, by first reading its size and then
|
* Reads a {@link QueryBuilder} from the current stream
|
||||||
* reading the individual objects using {@link #readNamedWriteable()}.
|
|
||||||
*/
|
*/
|
||||||
public <C> List<C> readNamedWriteableList() throws IOException {
|
public QueryBuilder readQuery() throws IOException {
|
||||||
List<C> list = new ArrayList<>();
|
return readNamedWriteable(QueryBuilder.class);
|
||||||
int size = readInt();
|
|
||||||
for (int i = 0; i < size; i++) {
|
|
||||||
C obj = readNamedWriteable();
|
|
||||||
list.add(obj);
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static StreamInput wrap(BytesReference reference) {
|
public static StreamInput wrap(BytesReference reference) {
|
||||||
|
@ -605,5 +591,4 @@ public abstract class StreamInput extends InputStream {
|
||||||
public static StreamInput wrap(byte[] bytes, int offset, int length) {
|
public static StreamInput wrap(byte[] bytes, int offset, int length) {
|
||||||
return new InputStreamStreamInput(new ByteArrayInputStream(bytes, offset, length));
|
return new InputStreamStreamInput(new ByteArrayInputStream(bytes, offset, length));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
|
|
||||||
package org.elasticsearch.common.io.stream;
|
package org.elasticsearch.common.io.stream;
|
||||||
|
|
||||||
import com.vividsolutions.jts.util.Assert;
|
|
||||||
import org.apache.lucene.index.CorruptIndexException;
|
import org.apache.lucene.index.CorruptIndexException;
|
||||||
import org.apache.lucene.index.IndexFormatTooNewException;
|
import org.apache.lucene.index.IndexFormatTooNewException;
|
||||||
import org.apache.lucene.index.IndexFormatTooOldException;
|
import org.apache.lucene.index.IndexFormatTooOldException;
|
||||||
|
@ -33,6 +32,7 @@ import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
import org.elasticsearch.common.regex.Regex;
|
import org.elasticsearch.common.regex.Regex;
|
||||||
import org.elasticsearch.common.text.Text;
|
import org.elasticsearch.common.text.Text;
|
||||||
|
import org.elasticsearch.index.query.QueryBuilder;
|
||||||
import org.joda.time.ReadableInstant;
|
import org.joda.time.ReadableInstant;
|
||||||
|
|
||||||
import java.io.EOFException;
|
import java.io.EOFException;
|
||||||
|
@ -618,19 +618,15 @@ public abstract class StreamOutput extends OutputStream {
|
||||||
/**
|
/**
|
||||||
* Writes a {@link NamedWriteable} to the current stream, by first writing its name and then the object itself
|
* Writes a {@link NamedWriteable} to the current stream, by first writing its name and then the object itself
|
||||||
*/
|
*/
|
||||||
public void writeNamedWriteable(NamedWriteable namedWriteable) throws IOException {
|
void writeNamedWriteable(NamedWriteable namedWriteable) throws IOException {
|
||||||
writeString(namedWriteable.getName());
|
writeString(namedWriteable.getWriteableName());
|
||||||
namedWriteable.writeTo(this);
|
namedWriteable.writeTo(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a list of {@link NamedWriteable} to the current stream, by first writing its size and then iterating over the objects
|
* Writes a {@link QueryBuilder} to the current stream
|
||||||
* in the list
|
|
||||||
*/
|
*/
|
||||||
public void writeNamedWriteableList(List<? extends NamedWriteable> list) throws IOException {
|
public void writeQuery(QueryBuilder queryBuilder) throws IOException {
|
||||||
writeInt(list.size());
|
writeNamedWriteable(queryBuilder);
|
||||||
for (NamedWriteable obj : list) {
|
|
||||||
writeNamedWriteable(obj);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -257,4 +257,42 @@ public abstract class AbstractQueryBuilder<QB extends AbstractQueryBuilder> exte
|
||||||
}
|
}
|
||||||
return validationException;
|
return validationException;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
//default impl returns the same as writeable name, but we keep the distinction between the two just to make sure
|
||||||
|
return getWriteableName();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final void writeQueries(StreamOutput out, List<? extends QueryBuilder> queries) throws IOException {
|
||||||
|
out.writeVInt(queries.size());
|
||||||
|
for (QueryBuilder query : queries) {
|
||||||
|
out.writeQuery(query);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final List<QueryBuilder> readQueries(StreamInput in) throws IOException {
|
||||||
|
List<QueryBuilder> queries = new ArrayList<>();
|
||||||
|
int size = in.readVInt();
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
queries.add(in.readQuery());
|
||||||
|
}
|
||||||
|
return queries;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final void writeOptionalQuery(StreamOutput out, QueryBuilder query) throws IOException {
|
||||||
|
if (query == null) {
|
||||||
|
out.writeBoolean(false);
|
||||||
|
} else {
|
||||||
|
out.writeBoolean(true);
|
||||||
|
out.writeQuery(query);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final QueryBuilder readOptionalQuery(StreamInput in) throws IOException {
|
||||||
|
if (in.readBoolean()) {
|
||||||
|
return in.readQuery();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,7 +111,7 @@ public class AndQueryBuilder extends AbstractQueryBuilder<AndQueryBuilder> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ public class AndQueryBuilder extends AbstractQueryBuilder<AndQueryBuilder> {
|
||||||
@Override
|
@Override
|
||||||
protected AndQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
protected AndQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
AndQueryBuilder andQueryBuilder = new AndQueryBuilder();
|
AndQueryBuilder andQueryBuilder = new AndQueryBuilder();
|
||||||
List<QueryBuilder> queryBuilders = in.readNamedWriteableList();
|
List<QueryBuilder> queryBuilders = readQueries(in);
|
||||||
for (QueryBuilder queryBuilder : queryBuilders) {
|
for (QueryBuilder queryBuilder : queryBuilders) {
|
||||||
andQueryBuilder.add(queryBuilder);
|
andQueryBuilder.add(queryBuilder);
|
||||||
}
|
}
|
||||||
|
@ -138,6 +138,6 @@ public class AndQueryBuilder extends AbstractQueryBuilder<AndQueryBuilder> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeNamedWriteableList(filters);
|
writeQueries(out, filters);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -249,7 +249,7 @@ public class BoolQueryBuilder extends AbstractQueryBuilder<BoolQueryBuilder> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,13 +308,13 @@ public class BoolQueryBuilder extends AbstractQueryBuilder<BoolQueryBuilder> {
|
||||||
@Override
|
@Override
|
||||||
protected BoolQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
protected BoolQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
|
BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
|
||||||
List<QueryBuilder> queryBuilders = in.readNamedWriteableList();
|
List<QueryBuilder> queryBuilders = readQueries(in);
|
||||||
boolQueryBuilder.mustClauses.addAll(queryBuilders);
|
boolQueryBuilder.mustClauses.addAll(queryBuilders);
|
||||||
queryBuilders = in.readNamedWriteableList();
|
queryBuilders = readQueries(in);
|
||||||
boolQueryBuilder.mustNotClauses.addAll(queryBuilders);
|
boolQueryBuilder.mustNotClauses.addAll(queryBuilders);
|
||||||
queryBuilders = in.readNamedWriteableList();
|
queryBuilders = readQueries(in);
|
||||||
boolQueryBuilder.shouldClauses.addAll(queryBuilders);
|
boolQueryBuilder.shouldClauses.addAll(queryBuilders);
|
||||||
queryBuilders = in.readNamedWriteableList();
|
queryBuilders = readQueries(in);
|
||||||
boolQueryBuilder.filterClauses.addAll(queryBuilders);
|
boolQueryBuilder.filterClauses.addAll(queryBuilders);
|
||||||
boolQueryBuilder.adjustPureNegative = in.readBoolean();
|
boolQueryBuilder.adjustPureNegative = in.readBoolean();
|
||||||
boolQueryBuilder.disableCoord = in.readBoolean();
|
boolQueryBuilder.disableCoord = in.readBoolean();
|
||||||
|
@ -325,10 +325,10 @@ public class BoolQueryBuilder extends AbstractQueryBuilder<BoolQueryBuilder> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeNamedWriteableList(mustClauses);
|
writeQueries(out, mustClauses);
|
||||||
out.writeNamedWriteableList(mustNotClauses);
|
writeQueries(out, mustNotClauses);
|
||||||
out.writeNamedWriteableList(shouldClauses);
|
writeQueries(out, shouldClauses);
|
||||||
out.writeNamedWriteableList(filterClauses);
|
writeQueries(out, filterClauses);
|
||||||
out.writeBoolean(adjustPureNegative);
|
out.writeBoolean(adjustPureNegative);
|
||||||
out.writeBoolean(disableCoord);
|
out.writeBoolean(disableCoord);
|
||||||
out.writeOptionalString(minimumShouldMatch);
|
out.writeOptionalString(minimumShouldMatch);
|
||||||
|
|
|
@ -124,7 +124,7 @@ public class BoostingQueryBuilder extends AbstractQueryBuilder<BoostingQueryBuil
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,8 +155,8 @@ public class BoostingQueryBuilder extends AbstractQueryBuilder<BoostingQueryBuil
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected BoostingQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
protected BoostingQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
QueryBuilder positiveQuery = in.readNamedWriteable();
|
QueryBuilder positiveQuery = in.readQuery();
|
||||||
QueryBuilder negativeQuery = in.readNamedWriteable();
|
QueryBuilder negativeQuery = in.readQuery();
|
||||||
BoostingQueryBuilder boostingQuery = new BoostingQueryBuilder(positiveQuery, negativeQuery);
|
BoostingQueryBuilder boostingQuery = new BoostingQueryBuilder(positiveQuery, negativeQuery);
|
||||||
boostingQuery.negativeBoost = in.readFloat();
|
boostingQuery.negativeBoost = in.readFloat();
|
||||||
return boostingQuery;
|
return boostingQuery;
|
||||||
|
@ -164,8 +164,8 @@ public class BoostingQueryBuilder extends AbstractQueryBuilder<BoostingQueryBuil
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeNamedWriteable(positiveQuery);
|
out.writeQuery(positiveQuery);
|
||||||
out.writeNamedWriteable(negativeQuery);
|
out.writeQuery(negativeQuery);
|
||||||
out.writeFloat(negativeBoost);
|
out.writeFloat(negativeBoost);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -223,7 +223,7 @@ public class CommonTermsQueryBuilder extends AbstractQueryBuilder<CommonTermsQue
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,7 @@ public class ConstantScoreQueryBuilder extends AbstractQueryBuilder<ConstantScor
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,12 +104,12 @@ public class ConstantScoreQueryBuilder extends AbstractQueryBuilder<ConstantScor
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ConstantScoreQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
protected ConstantScoreQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
QueryBuilder innerFilterBuilder = in.readNamedWriteable();
|
QueryBuilder innerFilterBuilder = in.readQuery();
|
||||||
return new ConstantScoreQueryBuilder(innerFilterBuilder);
|
return new ConstantScoreQueryBuilder(innerFilterBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeNamedWriteable(filterBuilder);
|
out.writeQuery(filterBuilder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,7 +114,7 @@ public class DisMaxQueryBuilder extends AbstractQueryBuilder<DisMaxQueryBuilder>
|
||||||
@Override
|
@Override
|
||||||
protected DisMaxQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
protected DisMaxQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
DisMaxQueryBuilder disMax = new DisMaxQueryBuilder();
|
DisMaxQueryBuilder disMax = new DisMaxQueryBuilder();
|
||||||
List<QueryBuilder> queryBuilders = in.readNamedWriteableList();
|
List<QueryBuilder> queryBuilders = readQueries(in);
|
||||||
disMax.queries.addAll(queryBuilders);
|
disMax.queries.addAll(queryBuilders);
|
||||||
disMax.tieBreaker = in.readFloat();
|
disMax.tieBreaker = in.readFloat();
|
||||||
return disMax;
|
return disMax;
|
||||||
|
@ -122,7 +122,7 @@ public class DisMaxQueryBuilder extends AbstractQueryBuilder<DisMaxQueryBuilder>
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeNamedWriteableList(queries);
|
writeQueries(out, queries);
|
||||||
out.writeFloat(tieBreaker);
|
out.writeFloat(tieBreaker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ public class DisMaxQueryBuilder extends AbstractQueryBuilder<DisMaxQueryBuilder>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,10 +50,15 @@ public class EmptyQueryBuilder extends ToXContentToBytes implements QueryBuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return getWriteableName();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
|
|
|
@ -138,7 +138,7 @@ public class ExistsQueryBuilder extends AbstractQueryBuilder<ExistsQueryBuilder>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,18 +95,18 @@ public class FQueryFilterBuilder extends AbstractQueryBuilder<FQueryFilterBuilde
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected FQueryFilterBuilder doReadFrom(StreamInput in) throws IOException {
|
protected FQueryFilterBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
QueryBuilder innerQueryBuilder = in.readNamedWriteable();
|
QueryBuilder innerQueryBuilder = in.readQuery();
|
||||||
FQueryFilterBuilder fquery = new FQueryFilterBuilder(innerQueryBuilder);
|
FQueryFilterBuilder fquery = new FQueryFilterBuilder(innerQueryBuilder);
|
||||||
return fquery;
|
return fquery;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeNamedWriteable(queryBuilder);
|
out.writeQuery(queryBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,13 +103,13 @@ public class FieldMaskingSpanQueryBuilder extends AbstractQueryBuilder<FieldMask
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected FieldMaskingSpanQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
protected FieldMaskingSpanQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
QueryBuilder innerQueryBuilder = in.readNamedWriteable();
|
QueryBuilder innerQueryBuilder = in.readQuery();
|
||||||
return new FieldMaskingSpanQueryBuilder((SpanQueryBuilder) innerQueryBuilder, in.readString());
|
return new FieldMaskingSpanQueryBuilder((SpanQueryBuilder) innerQueryBuilder, in.readString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeNamedWriteable(queryBuilder);
|
out.writeQuery(queryBuilder);
|
||||||
out.writeString(fieldName);
|
out.writeString(fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ public class FieldMaskingSpanQueryBuilder extends AbstractQueryBuilder<FieldMask
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,21 +138,21 @@ public class FilteredQueryBuilder extends AbstractQueryBuilder<FilteredQueryBuil
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FilteredQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
public FilteredQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
QueryBuilder query = in.readNamedWriteable();
|
QueryBuilder query = in.readQuery();
|
||||||
QueryBuilder filter = in.readNamedWriteable();
|
QueryBuilder filter = in.readQuery();
|
||||||
FilteredQueryBuilder qb = new FilteredQueryBuilder(query, filter);
|
FilteredQueryBuilder qb = new FilteredQueryBuilder(query, filter);
|
||||||
return qb;
|
return qb;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doWriteTo(StreamOutput out) throws IOException {
|
public void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeNamedWriteable(queryBuilder);
|
out.writeQuery(queryBuilder);
|
||||||
out.writeNamedWriteable(filterBuilder);
|
out.writeQuery(filterBuilder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,7 +171,7 @@ public class FuzzyQueryBuilder extends AbstractQueryBuilder<FuzzyQueryBuilder> i
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,7 +168,7 @@ public class GeoBoundingBoxQueryBuilder extends AbstractQueryBuilder<GeoBounding
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,7 +111,7 @@ public class GeoDistanceQueryBuilder extends AbstractQueryBuilder<GeoDistanceQue
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,7 +150,7 @@ public class GeoDistanceRangeQueryBuilder extends AbstractQueryBuilder<GeoDistan
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ public class GeoPolygonQueryBuilder extends AbstractQueryBuilder<GeoPolygonQuery
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -174,7 +174,7 @@ public class GeoShapeQueryBuilder extends AbstractQueryBuilder<GeoShapeQueryBuil
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,7 +169,7 @@ public class GeohashCellQuery {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,7 +117,7 @@ public class HasChildQueryBuilder extends AbstractQueryBuilder<HasChildQueryBuil
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ public class HasParentQueryBuilder extends AbstractQueryBuilder<HasParentQueryBu
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,7 +119,7 @@ public class IdsQueryBuilder extends AbstractQueryBuilder<IdsQueryBuilder> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class IndicesQueryBuilder extends AbstractQueryBuilder<IndicesQueryBuilde
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,7 @@ public class LimitQueryBuilder extends AbstractQueryBuilder<LimitQueryBuilder> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class MatchAllQueryBuilder extends AbstractQueryBuilder<MatchAllQueryBuil
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -249,7 +249,7 @@ public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,7 +105,7 @@ public class MissingQueryBuilder extends AbstractQueryBuilder<MissingQueryBuilde
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -418,7 +418,7 @@ public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder<MoreLikeThisQ
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -380,7 +380,7 @@ public class MultiMatchQueryBuilder extends AbstractQueryBuilder<MultiMatchQuery
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,7 @@ public class NestedQueryBuilder extends AbstractQueryBuilder<NestedQueryBuilder>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final String getName() {
|
public final String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,17 +85,17 @@ public class NotQueryBuilder extends AbstractQueryBuilder<NotQueryBuilder> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected NotQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
protected NotQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
QueryBuilder queryBuilder = in.readNamedWriteable();
|
QueryBuilder queryBuilder = in.readQuery();
|
||||||
return new NotQueryBuilder(queryBuilder);
|
return new NotQueryBuilder(queryBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeNamedWriteable(filter);
|
out.writeQuery(filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,7 +108,7 @@ public class OrQueryBuilder extends AbstractQueryBuilder<OrQueryBuilder> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ public class OrQueryBuilder extends AbstractQueryBuilder<OrQueryBuilder> {
|
||||||
@Override
|
@Override
|
||||||
protected OrQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
protected OrQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
OrQueryBuilder orQueryBuilder = new OrQueryBuilder();
|
OrQueryBuilder orQueryBuilder = new OrQueryBuilder();
|
||||||
List<QueryBuilder> queryBuilders = in.readNamedWriteableList();
|
List<QueryBuilder> queryBuilders = readQueries(in);
|
||||||
for (QueryBuilder queryBuilder : queryBuilders) {
|
for (QueryBuilder queryBuilder : queryBuilders) {
|
||||||
orQueryBuilder.add(queryBuilder);
|
orQueryBuilder.add(queryBuilder);
|
||||||
}
|
}
|
||||||
|
@ -135,6 +135,6 @@ public class OrQueryBuilder extends AbstractQueryBuilder<OrQueryBuilder> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeNamedWriteableList(filters);
|
writeQueries(out, filters);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ public class PrefixQueryBuilder extends AbstractQueryBuilder<PrefixQueryBuilder>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,12 +58,12 @@ public interface QueryBuilder<QB extends QueryBuilder> extends NamedWriteable<QB
|
||||||
BytesReference buildAsBytes();
|
BytesReference buildAsBytes();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the query name for the query.
|
* Sets the arbitrary name to be assigned to the query (see named queries).
|
||||||
*/
|
*/
|
||||||
QB queryName(String queryName);
|
QB queryName(String queryName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the query name for the query.
|
* Returns the arbitrary name assigned to the query (see named queries).
|
||||||
*/
|
*/
|
||||||
String queryName();
|
String queryName();
|
||||||
|
|
||||||
|
@ -77,4 +77,9 @@ public interface QueryBuilder<QB extends QueryBuilder> extends NamedWriteable<QB
|
||||||
* weightings) have their score multiplied by the boost provided.
|
* weightings) have their score multiplied by the boost provided.
|
||||||
*/
|
*/
|
||||||
QB boost(float boost);
|
QB boost(float boost);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name that identifies uniquely the query
|
||||||
|
*/
|
||||||
|
String getName();
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,17 +91,17 @@ public class QueryFilterBuilder extends AbstractQueryBuilder<QueryFilterBuilder>
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected QueryFilterBuilder doReadFrom(StreamInput in) throws IOException {
|
protected QueryFilterBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
QueryBuilder innerQueryBuilder = in.readNamedWriteable();
|
QueryBuilder innerQueryBuilder = in.readQuery();
|
||||||
return new QueryFilterBuilder(innerQueryBuilder);
|
return new QueryFilterBuilder(innerQueryBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeNamedWriteable(queryBuilder);
|
out.writeQuery(queryBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -406,7 +406,7 @@ public class QueryStringQueryBuilder extends AbstractQueryBuilder<QueryStringQue
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class QueryWrappingQueryBuilder extends AbstractQueryBuilder<QueryWrappin
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
// this should not be called since we overwrite BaseQueryBuilder#toQuery() in this class
|
// this should not be called since we overwrite BaseQueryBuilder#toQuery() in this class
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -238,7 +238,7 @@ public class RangeQueryBuilder extends AbstractQueryBuilder<RangeQueryBuilder> i
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -144,7 +144,7 @@ public class RegexpQueryBuilder extends AbstractQueryBuilder<RegexpQueryBuilder>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class ScriptQueryBuilder extends AbstractQueryBuilder<ScriptQueryBuilder>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -349,7 +349,7 @@ public class SimpleQueryStringBuilder extends AbstractQueryBuilder<SimpleQuerySt
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -100,15 +100,15 @@ public class SpanContainingQueryBuilder extends AbstractQueryBuilder<SpanContain
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SpanContainingQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
protected SpanContainingQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
SpanQueryBuilder big = in.readNamedWriteable();
|
SpanQueryBuilder big = (SpanQueryBuilder)in.readQuery();
|
||||||
SpanQueryBuilder little = in.readNamedWriteable();
|
SpanQueryBuilder little = (SpanQueryBuilder)in.readQuery();
|
||||||
return new SpanContainingQueryBuilder(big, little);
|
return new SpanContainingQueryBuilder(big, little);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeNamedWriteable(big);
|
out.writeQuery(big);
|
||||||
out.writeNamedWriteable(little);
|
out.writeQuery(little);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -123,7 +123,7 @@ public class SpanContainingQueryBuilder extends AbstractQueryBuilder<SpanContain
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,14 +98,14 @@ public class SpanFirstQueryBuilder extends AbstractQueryBuilder<SpanFirstQueryBu
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SpanFirstQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
protected SpanFirstQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
SpanQueryBuilder matchBuilder = in.readNamedWriteable();
|
SpanQueryBuilder matchBuilder = (SpanQueryBuilder)in.readQuery();
|
||||||
int end = in.readInt();
|
int end = in.readInt();
|
||||||
return new SpanFirstQueryBuilder(matchBuilder, end);
|
return new SpanFirstQueryBuilder(matchBuilder, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeNamedWriteable(matchBuilder);
|
out.writeQuery(matchBuilder);
|
||||||
out.writeInt(end);
|
out.writeInt(end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ public class SpanFirstQueryBuilder extends AbstractQueryBuilder<SpanFirstQueryBu
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,13 +79,13 @@ public class SpanMultiTermQueryBuilder extends AbstractQueryBuilder<SpanMultiTer
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SpanMultiTermQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
protected SpanMultiTermQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
MultiTermQueryBuilder multiTermBuilder = in.readNamedWriteable();
|
MultiTermQueryBuilder multiTermBuilder = (MultiTermQueryBuilder)in.readQuery();
|
||||||
return new SpanMultiTermQueryBuilder(multiTermBuilder);
|
return new SpanMultiTermQueryBuilder(multiTermBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeNamedWriteable(multiTermQueryBuilder);
|
out.writeQuery(multiTermQueryBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -99,7 +99,7 @@ public class SpanMultiTermQueryBuilder extends AbstractQueryBuilder<SpanMultiTer
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class SpanNearQueryBuilder extends AbstractQueryBuilder<SpanNearQueryBuil
|
||||||
/** Default for flag controlling whether payloads are collected */
|
/** Default for flag controlling whether payloads are collected */
|
||||||
public static boolean DEFAULT_COLLECT_PAYLOADS = true;
|
public static boolean DEFAULT_COLLECT_PAYLOADS = true;
|
||||||
|
|
||||||
private final ArrayList<SpanQueryBuilder> clauses = new ArrayList<>();
|
private final List<SpanQueryBuilder> clauses = new ArrayList<>();
|
||||||
|
|
||||||
private final int slop;
|
private final int slop;
|
||||||
|
|
||||||
|
@ -159,9 +159,9 @@ public class SpanNearQueryBuilder extends AbstractQueryBuilder<SpanNearQueryBuil
|
||||||
@Override
|
@Override
|
||||||
protected SpanNearQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
protected SpanNearQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
SpanNearQueryBuilder queryBuilder = new SpanNearQueryBuilder(in.readVInt());
|
SpanNearQueryBuilder queryBuilder = new SpanNearQueryBuilder(in.readVInt());
|
||||||
List<SpanQueryBuilder> clauses = in.readNamedWriteableList();
|
List<QueryBuilder> clauses = readQueries(in);
|
||||||
for (SpanQueryBuilder subClause : clauses) {
|
for (QueryBuilder subClause : clauses) {
|
||||||
queryBuilder.clause(subClause);
|
queryBuilder.clauses.add((SpanQueryBuilder)subClause);
|
||||||
}
|
}
|
||||||
queryBuilder.collectPayloads = in.readBoolean();
|
queryBuilder.collectPayloads = in.readBoolean();
|
||||||
queryBuilder.inOrder = in.readBoolean();
|
queryBuilder.inOrder = in.readBoolean();
|
||||||
|
@ -172,7 +172,7 @@ public class SpanNearQueryBuilder extends AbstractQueryBuilder<SpanNearQueryBuil
|
||||||
@Override
|
@Override
|
||||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeVInt(slop);
|
out.writeVInt(slop);
|
||||||
out.writeNamedWriteableList(clauses);
|
writeQueries(out, clauses);
|
||||||
out.writeBoolean(collectPayloads);
|
out.writeBoolean(collectPayloads);
|
||||||
out.writeBoolean(inOrder);
|
out.writeBoolean(inOrder);
|
||||||
}
|
}
|
||||||
|
@ -191,7 +191,7 @@ public class SpanNearQueryBuilder extends AbstractQueryBuilder<SpanNearQueryBuil
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,8 +159,8 @@ public class SpanNotQueryBuilder extends AbstractQueryBuilder<SpanNotQueryBuilde
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SpanNotQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
protected SpanNotQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
SpanQueryBuilder include = in.readNamedWriteable();
|
SpanQueryBuilder include = (SpanQueryBuilder)in.readQuery();
|
||||||
SpanQueryBuilder exclude = in.readNamedWriteable();
|
SpanQueryBuilder exclude = (SpanQueryBuilder)in.readQuery();
|
||||||
SpanNotQueryBuilder queryBuilder = new SpanNotQueryBuilder(include, exclude);
|
SpanNotQueryBuilder queryBuilder = new SpanNotQueryBuilder(include, exclude);
|
||||||
queryBuilder.pre(in.readVInt());
|
queryBuilder.pre(in.readVInt());
|
||||||
queryBuilder.post(in.readVInt());
|
queryBuilder.post(in.readVInt());
|
||||||
|
@ -169,8 +169,8 @@ public class SpanNotQueryBuilder extends AbstractQueryBuilder<SpanNotQueryBuilde
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeNamedWriteable(include);
|
out.writeQuery(include);
|
||||||
out.writeNamedWriteable(exclude);
|
out.writeQuery(exclude);
|
||||||
out.writeVInt(pre);
|
out.writeVInt(pre);
|
||||||
out.writeVInt(post);
|
out.writeVInt(post);
|
||||||
}
|
}
|
||||||
|
@ -189,7 +189,7 @@ public class SpanNotQueryBuilder extends AbstractQueryBuilder<SpanNotQueryBuilde
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ public class SpanOrQueryBuilder extends AbstractQueryBuilder<SpanOrQueryBuilder>
|
||||||
|
|
||||||
public static final String NAME = "span_or";
|
public static final String NAME = "span_or";
|
||||||
|
|
||||||
private final ArrayList<SpanQueryBuilder> clauses = new ArrayList<>();
|
private final List<SpanQueryBuilder> clauses = new ArrayList<>();
|
||||||
|
|
||||||
static final SpanOrQueryBuilder PROTOTYPE = new SpanOrQueryBuilder();
|
static final SpanOrQueryBuilder PROTOTYPE = new SpanOrQueryBuilder();
|
||||||
|
|
||||||
|
@ -96,9 +96,9 @@ public class SpanOrQueryBuilder extends AbstractQueryBuilder<SpanOrQueryBuilder>
|
||||||
@Override
|
@Override
|
||||||
protected SpanOrQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
protected SpanOrQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
SpanOrQueryBuilder queryBuilder = new SpanOrQueryBuilder();
|
SpanOrQueryBuilder queryBuilder = new SpanOrQueryBuilder();
|
||||||
List<SpanQueryBuilder> clauses = in.readNamedWriteableList();
|
List<QueryBuilder> clauses = readQueries(in);
|
||||||
for (SpanQueryBuilder subClause : clauses) {
|
for (QueryBuilder subClause : clauses) {
|
||||||
queryBuilder.clause(subClause);
|
queryBuilder.clauses.add((SpanQueryBuilder)subClause);
|
||||||
}
|
}
|
||||||
return queryBuilder;
|
return queryBuilder;
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ public class SpanOrQueryBuilder extends AbstractQueryBuilder<SpanOrQueryBuilder>
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeNamedWriteableList(clauses);
|
writeQueries(out, clauses);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -120,7 +120,7 @@ public class SpanOrQueryBuilder extends AbstractQueryBuilder<SpanOrQueryBuilder>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,7 @@ public class SpanTermQueryBuilder extends BaseTermQueryBuilder<SpanTermQueryBuil
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,15 +105,15 @@ public class SpanWithinQueryBuilder extends AbstractQueryBuilder<SpanWithinQuery
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SpanWithinQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
protected SpanWithinQueryBuilder doReadFrom(StreamInput in) throws IOException {
|
||||||
SpanQueryBuilder big = in.readNamedWriteable();
|
SpanQueryBuilder big = (SpanQueryBuilder)in.readQuery();
|
||||||
SpanQueryBuilder little = in.readNamedWriteable();
|
SpanQueryBuilder little = (SpanQueryBuilder)in.readQuery();
|
||||||
return new SpanWithinQueryBuilder(big, little);
|
return new SpanWithinQueryBuilder(big, little);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doWriteTo(StreamOutput out) throws IOException {
|
protected void doWriteTo(StreamOutput out) throws IOException {
|
||||||
out.writeNamedWriteable(big);
|
out.writeQuery(big);
|
||||||
out.writeNamedWriteable(little);
|
out.writeQuery(little);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -128,7 +128,7 @@ public class SpanWithinQueryBuilder extends AbstractQueryBuilder<SpanWithinQuery
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ public class TemplateQueryBuilder extends AbstractQueryBuilder<TemplateQueryBuil
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,7 @@ public class TermQueryBuilder extends BaseTermQueryBuilder<TermQueryBuilder> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ public class TermsLookupQueryBuilder extends TermsQueryBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return TermsQueryBuilder.NAME;
|
return TermsQueryBuilder.NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -204,7 +204,7 @@ public class TermsQueryBuilder extends AbstractQueryBuilder<TermsQueryBuilder> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ public class TypeQueryBuilder extends AbstractQueryBuilder<TypeQueryBuilder> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,7 @@ public class WildcardQueryBuilder extends AbstractQueryBuilder<WildcardQueryBuil
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ public class WrapperQueryBuilder extends AbstractQueryBuilder<WrapperQueryBuilde
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,7 +188,7 @@ public class FunctionScoreQueryBuilder extends AbstractQueryBuilder<FunctionScor
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return FunctionScoreQueryParser.NAME;
|
return FunctionScoreQueryParser.NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.index.query.EmptyQueryBuilder;
|
import org.elasticsearch.index.query.EmptyQueryBuilder;
|
||||||
|
import org.elasticsearch.index.query.QueryBuilder;
|
||||||
import org.elasticsearch.index.query.QueryParser;
|
import org.elasticsearch.index.query.QueryParser;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -44,11 +45,11 @@ public class IndicesQueriesRegistry extends AbstractComponent {
|
||||||
for (String name : queryParser.names()) {
|
for (String name : queryParser.names()) {
|
||||||
queryParsers.put(name, queryParser);
|
queryParsers.put(name, queryParser);
|
||||||
}
|
}
|
||||||
namedWriteableRegistry.registerPrototype(queryParser.getBuilderPrototype());
|
namedWriteableRegistry.registerPrototype(QueryBuilder.class, queryParser.getBuilderPrototype());
|
||||||
}
|
}
|
||||||
// EmptyQueryBuilder is not registered as query parser but used internally.
|
// EmptyQueryBuilder is not registered as query parser but used internally.
|
||||||
// We need to register it with the NamedWriteableRegistry in order to serialize it
|
// We need to register it with the NamedWriteableRegistry in order to serialize it
|
||||||
namedWriteableRegistry.registerPrototype(EmptyQueryBuilder.PROTOTYPE);
|
namedWriteableRegistry.registerPrototype(QueryBuilder.class, EmptyQueryBuilder.PROTOTYPE);
|
||||||
this.queryParsers = ImmutableMap.copyOf(queryParsers);
|
this.queryParsers = ImmutableMap.copyOf(queryParsers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,6 @@ import org.elasticsearch.cluster.ClusterNameModule;
|
||||||
import org.elasticsearch.cluster.ClusterService;
|
import org.elasticsearch.cluster.ClusterService;
|
||||||
import org.elasticsearch.cluster.action.index.MappingUpdatedAction;
|
import org.elasticsearch.cluster.action.index.MappingUpdatedAction;
|
||||||
import org.elasticsearch.cluster.routing.RoutingService;
|
import org.elasticsearch.cluster.routing.RoutingService;
|
||||||
import org.elasticsearch.cluster.routing.allocation.AllocationService;
|
|
||||||
import org.elasticsearch.common.StopWatch;
|
import org.elasticsearch.common.StopWatch;
|
||||||
import org.elasticsearch.common.collect.Tuple;
|
import org.elasticsearch.common.collect.Tuple;
|
||||||
import org.elasticsearch.common.component.Lifecycle;
|
import org.elasticsearch.common.component.Lifecycle;
|
||||||
|
@ -85,8 +84,8 @@ import org.elasticsearch.script.ScriptModule;
|
||||||
import org.elasticsearch.script.ScriptService;
|
import org.elasticsearch.script.ScriptService;
|
||||||
import org.elasticsearch.search.SearchModule;
|
import org.elasticsearch.search.SearchModule;
|
||||||
import org.elasticsearch.search.SearchService;
|
import org.elasticsearch.search.SearchService;
|
||||||
import org.elasticsearch.snapshots.SnapshotsService;
|
|
||||||
import org.elasticsearch.snapshots.SnapshotShardsService;
|
import org.elasticsearch.snapshots.SnapshotShardsService;
|
||||||
|
import org.elasticsearch.snapshots.SnapshotsService;
|
||||||
import org.elasticsearch.threadpool.ThreadPool;
|
import org.elasticsearch.threadpool.ThreadPool;
|
||||||
import org.elasticsearch.threadpool.ThreadPoolModule;
|
import org.elasticsearch.threadpool.ThreadPoolModule;
|
||||||
import org.elasticsearch.transport.TransportModule;
|
import org.elasticsearch.transport.TransportModule;
|
||||||
|
@ -254,7 +253,7 @@ public class Node implements Releasable {
|
||||||
injector.getInstance(MonitorService.class).start();
|
injector.getInstance(MonitorService.class).start();
|
||||||
injector.getInstance(RestController.class).start();
|
injector.getInstance(RestController.class).start();
|
||||||
|
|
||||||
// TODO hack around circular dependecncies problems
|
// TODO hack around circular dependencies problems
|
||||||
injector.getInstance(GatewayAllocator.class).setReallocation(injector.getInstance(ClusterService.class), injector.getInstance(RoutingService.class));
|
injector.getInstance(GatewayAllocator.class).setReallocation(injector.getInstance(ClusterService.class), injector.getInstance(RoutingService.class));
|
||||||
|
|
||||||
DiscoveryService discoService = injector.getInstance(DiscoveryService.class).start();
|
DiscoveryService discoService = injector.getInstance(DiscoveryService.class).start();
|
||||||
|
|
|
@ -26,8 +26,9 @@ import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
||||||
import org.elasticsearch.common.component.Lifecycle;
|
import org.elasticsearch.common.component.Lifecycle;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.io.stream.*;
|
|
||||||
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
||||||
|
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput;
|
||||||
|
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.transport.BoundTransportAddress;
|
import org.elasticsearch.common.transport.BoundTransportAddress;
|
||||||
|
@ -226,7 +227,7 @@ public class LocalTransport extends AbstractLifecycleComponent<Transport> implem
|
||||||
Transports.assertTransportThread();
|
Transports.assertTransportThread();
|
||||||
try {
|
try {
|
||||||
transportServiceAdapter.received(data.length);
|
transportServiceAdapter.received(data.length);
|
||||||
StreamInput stream = new FilterStreamInput(StreamInput.wrap(data), namedWriteableRegistry);
|
StreamInput stream = StreamInput.wrap(data);
|
||||||
stream.setVersion(version);
|
stream.setVersion(version);
|
||||||
|
|
||||||
long requestId = stream.readLong();
|
long requestId = stream.readLong();
|
||||||
|
@ -259,6 +260,7 @@ public class LocalTransport extends AbstractLifecycleComponent<Transport> implem
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleRequest(StreamInput stream, long requestId, LocalTransport sourceTransport, Version version) throws Exception {
|
private void handleRequest(StreamInput stream, long requestId, LocalTransport sourceTransport, Version version) throws Exception {
|
||||||
|
stream = new NamedWriteableAwareStreamInput(stream, namedWriteableRegistry);
|
||||||
final String action = stream.readString();
|
final String action = stream.readString();
|
||||||
transportServiceAdapter.onRequestReceived(requestId, action);
|
transportServiceAdapter.onRequestReceived(requestId, action);
|
||||||
final LocalTransportChannel transportChannel = new LocalTransportChannel(this, transportServiceAdapter, sourceTransport, action, requestId, version);
|
final LocalTransportChannel transportChannel = new LocalTransportChannel(this, transportServiceAdapter, sourceTransport, action, requestId, version);
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.elasticsearch.common.compress.CompressorFactory;
|
||||||
import org.elasticsearch.common.compress.NotCompressedException;
|
import org.elasticsearch.common.compress.NotCompressedException;
|
||||||
import org.elasticsearch.common.io.stream.FilterStreamInput;
|
import org.elasticsearch.common.io.stream.FilterStreamInput;
|
||||||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
||||||
|
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.logging.ESLogger;
|
import org.elasticsearch.common.logging.ESLogger;
|
||||||
import org.elasticsearch.common.transport.InetSocketTransportAddress;
|
import org.elasticsearch.common.transport.InetSocketTransportAddress;
|
||||||
|
@ -115,7 +116,6 @@ public class MessageChannelHandler extends SimpleChannelUpstreamHandler {
|
||||||
}
|
}
|
||||||
streamIn = compressor.streamInput(streamIn);
|
streamIn = compressor.streamInput(streamIn);
|
||||||
}
|
}
|
||||||
streamIn = new FilterStreamInput(streamIn, namedWriteableRegistry);
|
|
||||||
streamIn.setVersion(version);
|
streamIn.setVersion(version);
|
||||||
|
|
||||||
if (TransportStatus.isRequest(status)) {
|
if (TransportStatus.isRequest(status)) {
|
||||||
|
@ -235,6 +235,7 @@ public class MessageChannelHandler extends SimpleChannelUpstreamHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String handleRequest(Channel channel, StreamInput buffer, long requestId, Version version) throws IOException {
|
protected String handleRequest(Channel channel, StreamInput buffer, long requestId, Version version) throws IOException {
|
||||||
|
buffer = new NamedWriteableAwareStreamInput(buffer, transport.namedWriteableRegistry);
|
||||||
final String action = buffer.readString();
|
final String action = buffer.readString();
|
||||||
transportServiceAdapter.onRequestReceived(requestId, action);
|
transportServiceAdapter.onRequestReceived(requestId, action);
|
||||||
final NettyTransportChannel transportChannel = new NettyTransportChannel(transport, transportServiceAdapter, action, channel, requestId, version, profileName);
|
final NettyTransportChannel transportChannel = new NettyTransportChannel(transport, transportServiceAdapter, action, channel, requestId, version, profileName);
|
||||||
|
|
|
@ -24,7 +24,8 @@ import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import org.elasticsearch.*;
|
import org.elasticsearch.ExceptionsHelper;
|
||||||
|
import org.elasticsearch.Version;
|
||||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||||
import org.elasticsearch.common.Booleans;
|
import org.elasticsearch.common.Booleans;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
|
@ -150,6 +151,7 @@ public class NettyTransport extends AbstractLifecycleComponent<Transport> implem
|
||||||
protected volatile TransportServiceAdapter transportServiceAdapter;
|
protected volatile TransportServiceAdapter transportServiceAdapter;
|
||||||
protected volatile BoundTransportAddress boundAddress;
|
protected volatile BoundTransportAddress boundAddress;
|
||||||
protected final KeyedLock<String> connectionLock = new KeyedLock<>();
|
protected final KeyedLock<String> connectionLock = new KeyedLock<>();
|
||||||
|
protected final NamedWriteableRegistry namedWriteableRegistry;
|
||||||
|
|
||||||
// this lock is here to make sure we close this transport and disconnect all the client nodes
|
// this lock is here to make sure we close this transport and disconnect all the client nodes
|
||||||
// connections while no connect operations is going on... (this might help with 100% CPU when stopping the transport?)
|
// connections while no connect operations is going on... (this might help with 100% CPU when stopping the transport?)
|
||||||
|
@ -158,8 +160,6 @@ public class NettyTransport extends AbstractLifecycleComponent<Transport> implem
|
||||||
// package visibility for tests
|
// package visibility for tests
|
||||||
final ScheduledPing scheduledPing;
|
final ScheduledPing scheduledPing;
|
||||||
|
|
||||||
protected final NamedWriteableRegistry namedWriteableRegistry;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public NettyTransport(Settings settings, ThreadPool threadPool, NetworkService networkService, BigArrays bigArrays, Version version, NamedWriteableRegistry namedWriteableRegistry) {
|
public NettyTransport(Settings settings, ThreadPool threadPool, NetworkService networkService, BigArrays bigArrays, Version version, NamedWriteableRegistry namedWriteableRegistry) {
|
||||||
super(settings);
|
super(settings);
|
||||||
|
@ -973,7 +973,7 @@ public class NettyTransport extends AbstractLifecycleComponent<Transport> implem
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class ClientChannelPipelineFactory implements ChannelPipelineFactory {
|
protected static class ClientChannelPipelineFactory implements ChannelPipelineFactory {
|
||||||
protected NettyTransport nettyTransport;
|
protected final NettyTransport nettyTransport;
|
||||||
|
|
||||||
public ClientChannelPipelineFactory(NettyTransport nettyTransport) {
|
public ClientChannelPipelineFactory(NettyTransport nettyTransport) {
|
||||||
this.nettyTransport = nettyTransport;
|
this.nettyTransport = nettyTransport;
|
||||||
|
|
|
@ -17,23 +17,18 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.elasticsearch.common.io.streams;
|
package org.elasticsearch.common.io.stream;
|
||||||
|
|
||||||
import org.apache.lucene.util.Constants;
|
import org.apache.lucene.util.Constants;
|
||||||
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
|
||||||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
|
||||||
import org.elasticsearch.common.io.stream.FilterStreamInput;
|
|
||||||
import org.elasticsearch.common.lucene.BytesRefs;
|
import org.elasticsearch.common.lucene.BytesRefs;
|
||||||
import org.elasticsearch.common.util.BigArrays;
|
import org.elasticsearch.common.util.BigArrays;
|
||||||
import org.elasticsearch.index.query.MatchAllQueryBuilder;
|
|
||||||
import org.elasticsearch.index.query.QueryBuilder;
|
|
||||||
import org.elasticsearch.index.query.TermQueryBuilder;
|
|
||||||
import org.elasticsearch.test.ESTestCase;
|
import org.elasticsearch.test.ESTestCase;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.closeTo;
|
import static org.hamcrest.Matchers.closeTo;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
|
||||||
|
@ -314,43 +309,124 @@ public class BytesStreamsTests extends ESTestCase {
|
||||||
public void testNamedWriteable() throws IOException {
|
public void testNamedWriteable() throws IOException {
|
||||||
BytesStreamOutput out = new BytesStreamOutput();
|
BytesStreamOutput out = new BytesStreamOutput();
|
||||||
NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry();
|
NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry();
|
||||||
namedWriteableRegistry.registerPrototype(new TermQueryBuilder(null, null));
|
namedWriteableRegistry.registerPrototype(BaseNamedWriteable.class, new TestNamedWriteable(null, null));
|
||||||
TermQueryBuilder termQueryBuilder = new TermQueryBuilder(randomAsciiOfLengthBetween(1, 10), randomAsciiOfLengthBetween(1, 10));
|
TestNamedWriteable namedWriteableIn = new TestNamedWriteable(randomAsciiOfLengthBetween(1, 10), randomAsciiOfLengthBetween(1, 10));
|
||||||
out.writeNamedWriteable(termQueryBuilder);
|
out.writeNamedWriteable(namedWriteableIn);
|
||||||
StreamInput in = new FilterStreamInput(StreamInput.wrap(out.bytes().toBytes()), namedWriteableRegistry);
|
StreamInput in = new NamedWriteableAwareStreamInput(StreamInput.wrap(out.bytes().toBytes()), namedWriteableRegistry);
|
||||||
QueryBuilder queryBuilder = in.readNamedWriteable();
|
BaseNamedWriteable namedWriteableOut = in.readNamedWriteable(BaseNamedWriteable.class);
|
||||||
assertThat(queryBuilder, equalTo((QueryBuilder)termQueryBuilder));
|
assertEquals(namedWriteableOut, namedWriteableIn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNamedWriteableDuplicates() throws IOException {
|
public void testNamedWriteableDuplicates() throws IOException {
|
||||||
BytesStreamOutput out = new BytesStreamOutput();
|
|
||||||
NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry();
|
NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry();
|
||||||
namedWriteableRegistry.registerPrototype(new TermQueryBuilder(null, null));
|
namedWriteableRegistry.registerPrototype(BaseNamedWriteable.class, new TestNamedWriteable(null, null));
|
||||||
try {
|
try {
|
||||||
//wrong class, no registry available
|
namedWriteableRegistry.registerPrototype(BaseNamedWriteable.class, new TestNamedWriteable(null, null));
|
||||||
namedWriteableRegistry.registerPrototype(new TermQueryBuilder(null, null));
|
|
||||||
fail("registerPrototype should have failed");
|
fail("registerPrototype should have failed");
|
||||||
} catch(IllegalArgumentException e) {
|
} catch(IllegalArgumentException e) {
|
||||||
assertThat(e.getMessage(), equalTo("named writeable of type [" + TermQueryBuilder.class.getName() + "] with name [" + TermQueryBuilder.NAME + "] is already registered by type [" + TermQueryBuilder.class.getName() + "]"));
|
assertThat(e.getMessage(), equalTo("named writeable of type [" + TestNamedWriteable.class.getName() + "] with name [" + TestNamedWriteable.NAME + "] is already registered by type ["
|
||||||
|
+ TestNamedWriteable.class.getName() + "] within category [" + BaseNamedWriteable.class.getName() + "]"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNamedWriteableUnknownCategory() throws IOException {
|
||||||
|
BytesStreamOutput out = new BytesStreamOutput();
|
||||||
|
out.writeNamedWriteable(new TestNamedWriteable("test1", "test2"));
|
||||||
|
StreamInput in = new NamedWriteableAwareStreamInput(StreamInput.wrap(out.bytes().toBytes()), new NamedWriteableRegistry());
|
||||||
|
try {
|
||||||
|
//no named writeable registered with given name, can write but cannot read it back
|
||||||
|
in.readNamedWriteable(BaseNamedWriteable.class);
|
||||||
|
fail("read should have failed");
|
||||||
|
} catch(IllegalArgumentException e) {
|
||||||
|
assertThat(e.getMessage(), equalTo("unknown named writeable category [" + BaseNamedWriteable.class.getName() + "]"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNamedWriteableUnknownNamedWriteable() throws IOException {
|
public void testNamedWriteableUnknownNamedWriteable() throws IOException {
|
||||||
BytesStreamOutput out = new BytesStreamOutput();
|
|
||||||
NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry();
|
NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry();
|
||||||
out.writeNamedWriteable(new MatchAllQueryBuilder());
|
namedWriteableRegistry.registerPrototype(BaseNamedWriteable.class, new TestNamedWriteable(null, null));
|
||||||
StreamInput in = StreamInput.wrap(out.bytes().toBytes());
|
BytesStreamOutput out = new BytesStreamOutput();
|
||||||
if (randomBoolean()) {
|
out.writeNamedWriteable(new NamedWriteable() {
|
||||||
in = new FilterStreamInput(in, namedWriteableRegistry);
|
@Override
|
||||||
}
|
public String getWriteableName() {
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object readFrom(StreamInput in) throws IOException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
StreamInput in = new NamedWriteableAwareStreamInput(StreamInput.wrap(out.bytes().toBytes()), namedWriteableRegistry);
|
||||||
try {
|
try {
|
||||||
//no match_all named writeable registered, can write but cannot read it back
|
//no named writeable registered with given name under test category, can write but cannot read it back
|
||||||
in.readNamedWriteable();
|
in.readNamedWriteable(BaseNamedWriteable.class);
|
||||||
fail("read should have failed");
|
fail("read should have failed");
|
||||||
} catch(IllegalArgumentException e) {
|
} catch(IllegalArgumentException e) {
|
||||||
assertThat(e.getMessage(), equalTo("unknown named writeable with name [" + MatchAllQueryBuilder.NAME + "]"));
|
assertThat(e.getMessage(), equalTo("unknown named writeable with name [unknown] within category [" + BaseNamedWriteable.class.getName() + "]"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = UnsupportedOperationException.class)
|
||||||
|
public void testNamedWriteableNotSupportedWithoutWrapping() throws IOException {
|
||||||
|
BytesStreamOutput out = new BytesStreamOutput();
|
||||||
|
TestNamedWriteable testNamedWriteable = new TestNamedWriteable("test1", "test2");
|
||||||
|
out.writeNamedWriteable(testNamedWriteable);
|
||||||
|
StreamInput in = StreamInput.wrap(out.bytes().toBytes());
|
||||||
|
in.readNamedWriteable(BaseNamedWriteable.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static abstract class BaseNamedWriteable<T> implements NamedWriteable<T> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class TestNamedWriteable extends BaseNamedWriteable<TestNamedWriteable> {
|
||||||
|
|
||||||
|
private static final String NAME = "test-named-writeable";
|
||||||
|
|
||||||
|
private final String field1;
|
||||||
|
private final String field2;
|
||||||
|
|
||||||
|
TestNamedWriteable(String field1, String field2) {
|
||||||
|
this.field1 = field1;
|
||||||
|
this.field2 = field2;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getWriteableName() {
|
||||||
|
return NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
|
out.writeString(field1);
|
||||||
|
out.writeString(field2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TestNamedWriteable readFrom(StreamInput in) throws IOException {
|
||||||
|
return new TestNamedWriteable(in.readString(), in.readString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
TestNamedWriteable that = (TestNamedWriteable) o;
|
||||||
|
return Objects.equals(field1, that.field1) &&
|
||||||
|
Objects.equals(field2, that.field2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(field1, field2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,8 +93,8 @@ public class AndQueryBuilderTest extends BaseQueryTestCase<AndQueryBuilder> {
|
||||||
String queryString = "{ \"and\" : {}";
|
String queryString = "{ \"and\" : {}";
|
||||||
XContentParser parser = XContentFactory.xContent(queryString).createParser(queryString);
|
XContentParser parser = XContentFactory.xContent(queryString).createParser(queryString);
|
||||||
context.reset(parser);
|
context.reset(parser);
|
||||||
assertQueryHeader(parser, AndQueryBuilder.PROTOTYPE.getName());
|
assertQueryHeader(parser, AndQueryBuilder.NAME);
|
||||||
context.queryParser(AndQueryBuilder.PROTOTYPE.getName()).fromXContent(context);
|
context.queryParser(AndQueryBuilder.NAME).fromXContent(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -31,10 +31,7 @@ import org.elasticsearch.common.inject.AbstractModule;
|
||||||
import org.elasticsearch.common.inject.Injector;
|
import org.elasticsearch.common.inject.Injector;
|
||||||
import org.elasticsearch.common.inject.ModulesBuilder;
|
import org.elasticsearch.common.inject.ModulesBuilder;
|
||||||
import org.elasticsearch.common.inject.util.Providers;
|
import org.elasticsearch.common.inject.util.Providers;
|
||||||
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
import org.elasticsearch.common.io.stream.*;
|
||||||
import org.elasticsearch.common.io.stream.FilterStreamInput;
|
|
||||||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.settings.SettingsModule;
|
import org.elasticsearch.common.settings.SettingsModule;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
|
@ -237,8 +234,8 @@ public abstract class BaseQueryTestCase<QB extends AbstractQueryBuilder<QB>> ext
|
||||||
|
|
||||||
try (BytesStreamOutput output = new BytesStreamOutput()) {
|
try (BytesStreamOutput output = new BytesStreamOutput()) {
|
||||||
firstQuery.writeTo(output);
|
firstQuery.writeTo(output);
|
||||||
try (StreamInput in = new FilterStreamInput(StreamInput.wrap(output.bytes()), namedWriteableRegistry)) {
|
try (StreamInput in = new NamedWriteableAwareStreamInput(StreamInput.wrap(output.bytes()), namedWriteableRegistry)) {
|
||||||
QueryBuilder<? extends QueryBuilder> prototype = queryParserService.queryParser(firstQuery.getName()).getBuilderPrototype();
|
QueryBuilder<? extends QueryBuilder> prototype = queryParserService.queryParser(firstQuery.getWriteableName()).getBuilderPrototype();
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
QB secondQuery = (QB)prototype.readFrom(in);
|
QB secondQuery = (QB)prototype.readFrom(in);
|
||||||
//query _name never should affect the result of toQuery, we randomly set it to make sure
|
//query _name never should affect the result of toQuery, we randomly set it to make sure
|
||||||
|
@ -301,8 +298,8 @@ public abstract class BaseQueryTestCase<QB extends AbstractQueryBuilder<QB>> ext
|
||||||
QB testQuery = createTestQueryBuilder();
|
QB testQuery = createTestQueryBuilder();
|
||||||
try (BytesStreamOutput output = new BytesStreamOutput()) {
|
try (BytesStreamOutput output = new BytesStreamOutput()) {
|
||||||
testQuery.writeTo(output);
|
testQuery.writeTo(output);
|
||||||
try (StreamInput in = new FilterStreamInput(StreamInput.wrap(output.bytes()), namedWriteableRegistry)) {
|
try (StreamInput in = new NamedWriteableAwareStreamInput(StreamInput.wrap(output.bytes()), namedWriteableRegistry)) {
|
||||||
QueryBuilder<? extends QueryBuilder> prototype = queryParserService.queryParser(testQuery.getName()).getBuilderPrototype();
|
QueryBuilder<? extends QueryBuilder> prototype = queryParserService.queryParser(testQuery.getWriteableName()).getBuilderPrototype();
|
||||||
QueryBuilder deserializedQuery = prototype.readFrom(in);
|
QueryBuilder deserializedQuery = prototype.readFrom(in);
|
||||||
assertEquals(deserializedQuery, testQuery);
|
assertEquals(deserializedQuery, testQuery);
|
||||||
assertEquals(deserializedQuery.hashCode(), testQuery.hashCode());
|
assertEquals(deserializedQuery.hashCode(), testQuery.hashCode());
|
||||||
|
|
|
@ -59,7 +59,7 @@ public class ConstantScoreQueryBuilderTest extends BaseQueryTestCase<ConstantSco
|
||||||
@Test(expected=QueryParsingException.class)
|
@Test(expected=QueryParsingException.class)
|
||||||
public void testFilterElement() throws IOException {
|
public void testFilterElement() throws IOException {
|
||||||
QueryParseContext context = createParseContext();
|
QueryParseContext context = createParseContext();
|
||||||
String queryId = ConstantScoreQueryBuilder.PROTOTYPE.getName();
|
String queryId = ConstantScoreQueryBuilder.NAME;
|
||||||
String queryString = "{ \""+queryId+"\" : {}";
|
String queryString = "{ \""+queryId+"\" : {}";
|
||||||
XContentParser parser = XContentFactory.xContent(queryString).createParser(queryString);
|
XContentParser parser = XContentFactory.xContent(queryString).createParser(queryString);
|
||||||
context.reset(parser);
|
context.reset(parser);
|
||||||
|
|
|
@ -88,7 +88,7 @@ public class DisMaxQueryBuilderTest extends BaseQueryTestCase<DisMaxQueryBuilder
|
||||||
@Test
|
@Test
|
||||||
public void testInnerQueryReturnsNull() throws IOException {
|
public void testInnerQueryReturnsNull() throws IOException {
|
||||||
QueryParseContext context = createParseContext();
|
QueryParseContext context = createParseContext();
|
||||||
String queryId = ConstantScoreQueryBuilder.PROTOTYPE.getName();
|
String queryId = ConstantScoreQueryBuilder.NAME;
|
||||||
String queryString = "{ \""+queryId+"\" : { \"filter\" : { } }";
|
String queryString = "{ \""+queryId+"\" : { \"filter\" : { } }";
|
||||||
XContentParser parser = XContentFactory.xContent(queryString).createParser(queryString);
|
XContentParser parser = XContentFactory.xContent(queryString).createParser(queryString);
|
||||||
context.reset(parser);
|
context.reset(parser);
|
||||||
|
|
|
@ -75,8 +75,8 @@ public class FQueryFilterBuilderTest extends BaseQueryTestCase<FQueryFilterBuild
|
||||||
String queryString = "{ \"constant_score\" : { \"filter\" : {} }";
|
String queryString = "{ \"constant_score\" : { \"filter\" : {} }";
|
||||||
XContentParser parser = XContentFactory.xContent(queryString).createParser(queryString);
|
XContentParser parser = XContentFactory.xContent(queryString).createParser(queryString);
|
||||||
context.reset(parser);
|
context.reset(parser);
|
||||||
assertQueryHeader(parser, ConstantScoreQueryBuilder.PROTOTYPE.getName());
|
assertQueryHeader(parser, ConstantScoreQueryBuilder.NAME);
|
||||||
QueryBuilder innerQuery = context.queryParser(ConstantScoreQueryBuilder.PROTOTYPE.getName()).fromXContent(context);
|
QueryBuilder innerQuery = context.queryParser(ConstantScoreQueryBuilder.NAME).fromXContent(context);
|
||||||
|
|
||||||
// check that when wrapping this filter, toQuery() returns null
|
// check that when wrapping this filter, toQuery() returns null
|
||||||
FQueryFilterBuilder queryFilterQuery = new FQueryFilterBuilder(innerQuery);
|
FQueryFilterBuilder queryFilterQuery = new FQueryFilterBuilder(innerQuery);
|
||||||
|
|
|
@ -68,8 +68,8 @@ public class NotQueryBuilderTest extends BaseQueryTestCase<NotQueryBuilder> {
|
||||||
String queryString = "{ \"not\" : {}";
|
String queryString = "{ \"not\" : {}";
|
||||||
XContentParser parser = XContentFactory.xContent(queryString).createParser(queryString);
|
XContentParser parser = XContentFactory.xContent(queryString).createParser(queryString);
|
||||||
context.reset(parser);
|
context.reset(parser);
|
||||||
assertQueryHeader(parser, NotQueryBuilder.PROTOTYPE.getName());
|
assertQueryHeader(parser, NotQueryBuilder.NAME);
|
||||||
context.queryParser(NotQueryBuilder.PROTOTYPE.getName()).fromXContent(context);
|
context.queryParser(NotQueryBuilder.NAME).fromXContent(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -115,8 +115,8 @@ public class OrQueryBuilderTest extends BaseQueryTestCase<OrQueryBuilder> {
|
||||||
String queryString = "{ \"or\" : {}";
|
String queryString = "{ \"or\" : {}";
|
||||||
XContentParser parser = XContentFactory.xContent(queryString).createParser(queryString);
|
XContentParser parser = XContentFactory.xContent(queryString).createParser(queryString);
|
||||||
context.reset(parser);
|
context.reset(parser);
|
||||||
assertQueryHeader(parser, OrQueryBuilder.PROTOTYPE.getName());
|
assertQueryHeader(parser, OrQueryBuilder.NAME);
|
||||||
context.queryParser(OrQueryBuilder.PROTOTYPE.getName()).fromXContent(context);
|
context.queryParser(OrQueryBuilder.NAME).fromXContent(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -68,8 +68,8 @@ public class QueryFilterBuilderTest extends BaseQueryTestCase<QueryFilterBuilder
|
||||||
String queryString = "{ \"constant_score\" : { \"filter\" : {} }";
|
String queryString = "{ \"constant_score\" : { \"filter\" : {} }";
|
||||||
XContentParser parser = XContentFactory.xContent(queryString).createParser(queryString);
|
XContentParser parser = XContentFactory.xContent(queryString).createParser(queryString);
|
||||||
context.reset(parser);
|
context.reset(parser);
|
||||||
assertQueryHeader(parser, ConstantScoreQueryBuilder.PROTOTYPE.getName());
|
assertQueryHeader(parser, ConstantScoreQueryBuilder.NAME);
|
||||||
QueryBuilder innerQuery = context.queryParser(ConstantScoreQueryBuilder.PROTOTYPE.getName()).fromXContent(context);
|
QueryBuilder innerQuery = context.queryParser(ConstantScoreQueryBuilder.NAME).fromXContent(context);
|
||||||
|
|
||||||
// check that when wrapping this filter, toQuery() returns null
|
// check that when wrapping this filter, toQuery() returns null
|
||||||
QueryFilterBuilder queryFilterQuery = new QueryFilterBuilder(innerQuery);
|
QueryFilterBuilder queryFilterQuery = new QueryFilterBuilder(innerQuery);
|
||||||
|
|
|
@ -66,7 +66,7 @@ public class DummyQueryParserPlugin extends AbstractPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getWriteableName() {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,14 +70,12 @@ public abstract class AbstractSimpleTransportTests extends ESTestCase {
|
||||||
threadPool = new ThreadPool(getClass().getName());
|
threadPool = new ThreadPool(getClass().getName());
|
||||||
serviceA = build(
|
serviceA = build(
|
||||||
Settings.builder().put("name", "TS_A", TransportService.SETTING_TRACE_LOG_INCLUDE, "", TransportService.SETTING_TRACE_LOG_EXCLUDE, "NOTHING").build(),
|
Settings.builder().put("name", "TS_A", TransportService.SETTING_TRACE_LOG_INCLUDE, "", TransportService.SETTING_TRACE_LOG_EXCLUDE, "NOTHING").build(),
|
||||||
version0,
|
version0, new NamedWriteableRegistry()
|
||||||
namedWriteableRegistry
|
|
||||||
);
|
);
|
||||||
nodeA = new DiscoveryNode("TS_A", "TS_A", serviceA.boundAddress().publishAddress(), ImmutableMap.<String, String>of(), version0);
|
nodeA = new DiscoveryNode("TS_A", "TS_A", serviceA.boundAddress().publishAddress(), ImmutableMap.<String, String>of(), version0);
|
||||||
serviceB = build(
|
serviceB = build(
|
||||||
Settings.builder().put("name", "TS_B", TransportService.SETTING_TRACE_LOG_INCLUDE, "", TransportService.SETTING_TRACE_LOG_EXCLUDE, "NOTHING").build(),
|
Settings.builder().put("name", "TS_B", TransportService.SETTING_TRACE_LOG_INCLUDE, "", TransportService.SETTING_TRACE_LOG_EXCLUDE, "NOTHING").build(),
|
||||||
version1,
|
version1, new NamedWriteableRegistry()
|
||||||
namedWriteableRegistry
|
|
||||||
);
|
);
|
||||||
nodeB = new DiscoveryNode("TS_B", "TS_B", serviceB.boundAddress().publishAddress(), ImmutableMap.<String, String>of(), version1);
|
nodeB = new DiscoveryNode("TS_B", "TS_B", serviceB.boundAddress().publishAddress(), ImmutableMap.<String, String>of(), version1);
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,10 @@ import org.elasticsearch.common.util.BigArrays;
|
||||||
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
|
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
|
||||||
import org.elasticsearch.test.ESIntegTestCase;
|
import org.elasticsearch.test.ESIntegTestCase;
|
||||||
import org.elasticsearch.threadpool.ThreadPool;
|
import org.elasticsearch.threadpool.ThreadPool;
|
||||||
import org.elasticsearch.transport.*;
|
import org.elasticsearch.transport.ActionNotFoundTransportException;
|
||||||
|
import org.elasticsearch.transport.RequestHandlerRegistry;
|
||||||
|
import org.elasticsearch.transport.TransportModule;
|
||||||
|
import org.elasticsearch.transport.TransportRequest;
|
||||||
import org.jboss.netty.channel.Channel;
|
import org.jboss.netty.channel.Channel;
|
||||||
import org.jboss.netty.channel.ChannelPipeline;
|
import org.jboss.netty.channel.ChannelPipeline;
|
||||||
import org.jboss.netty.channel.ChannelPipelineFactory;
|
import org.jboss.netty.channel.ChannelPipelineFactory;
|
||||||
|
|
|
@ -20,7 +20,6 @@ package org.elasticsearch.transport.netty;
|
||||||
|
|
||||||
import com.carrotsearch.hppc.IntHashSet;
|
import com.carrotsearch.hppc.IntHashSet;
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
|
|
||||||
import org.elasticsearch.Version;
|
import org.elasticsearch.Version;
|
||||||
import org.elasticsearch.cache.recycler.PageCacheRecycler;
|
import org.elasticsearch.cache.recycler.PageCacheRecycler;
|
||||||
import org.elasticsearch.common.component.Lifecycle;
|
import org.elasticsearch.common.component.Lifecycle;
|
||||||
|
|
Loading…
Reference in New Issue