|
@@ -19,6 +19,7 @@
|
|
|
|
|
|
package org.elasticsearch.indices;
|
|
|
|
|
|
+import org.elasticsearch.Version;
|
|
|
import org.elasticsearch.common.ParsingException;
|
|
|
import org.elasticsearch.common.io.stream.StreamInput;
|
|
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
|
@@ -35,17 +36,12 @@ import java.util.Objects;
|
|
|
* Encapsulates the parameters needed to fetch terms.
|
|
|
*/
|
|
|
public class TermsLookup implements Writeable, ToXContent {
|
|
|
- private String index;
|
|
|
+ private final String index;
|
|
|
private final String type;
|
|
|
private final String id;
|
|
|
private final String path;
|
|
|
private String routing;
|
|
|
|
|
|
- public TermsLookup(TermsLookup copy) {
|
|
|
- this(copy.index, copy.type, copy.id, copy.path);
|
|
|
- this.routing = copy.routing;
|
|
|
- }
|
|
|
-
|
|
|
public TermsLookup(String index, String type, String id, String path) {
|
|
|
if (id == null) {
|
|
|
throw new IllegalArgumentException("[" + TermsQueryBuilder.NAME + "] query lookup element requires specifying the id.");
|
|
@@ -56,6 +52,9 @@ public class TermsLookup implements Writeable, ToXContent {
|
|
|
if (path == null) {
|
|
|
throw new IllegalArgumentException("[" + TermsQueryBuilder.NAME + "] query lookup element requires specifying the path.");
|
|
|
}
|
|
|
+ if (index == null) {
|
|
|
+ throw new IllegalArgumentException("[" + TermsQueryBuilder.NAME + "] query lookup element requires specifying the index.");
|
|
|
+ }
|
|
|
this.index = index;
|
|
|
this.type = type;
|
|
|
this.id = id;
|
|
@@ -69,7 +68,14 @@ public class TermsLookup implements Writeable, ToXContent {
|
|
|
type = in.readString();
|
|
|
id = in.readString();
|
|
|
path = in.readString();
|
|
|
- index = in.readOptionalString();
|
|
|
+ if (in.getVersion().onOrAfter(Version.V_6_0_0_beta1)) {
|
|
|
+ index = in.readString();
|
|
|
+ } else {
|
|
|
+ index = in.readOptionalString();
|
|
|
+ if (index == null) {
|
|
|
+ throw new IllegalStateException("index must not be null in a terms lookup");
|
|
|
+ }
|
|
|
+ }
|
|
|
routing = in.readOptionalString();
|
|
|
}
|
|
|
|
|
@@ -78,7 +84,11 @@ public class TermsLookup implements Writeable, ToXContent {
|
|
|
out.writeString(type);
|
|
|
out.writeString(id);
|
|
|
out.writeString(path);
|
|
|
- out.writeOptionalString(index);
|
|
|
+ if (out.getVersion().onOrAfter(Version.V_6_0_0_beta1)) {
|
|
|
+ out.writeString(index);
|
|
|
+ } else {
|
|
|
+ out.writeOptionalString(index);
|
|
|
+ }
|
|
|
out.writeOptionalString(routing);
|
|
|
}
|
|
|
|
|
@@ -86,11 +96,6 @@ public class TermsLookup implements Writeable, ToXContent {
|
|
|
return index;
|
|
|
}
|
|
|
|
|
|
- public TermsLookup index(String index) {
|
|
|
- this.index = index;
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
public String type() {
|
|
|
return type;
|
|
|
}
|
|
@@ -126,7 +131,7 @@ public class TermsLookup implements Writeable, ToXContent {
|
|
|
} else if (token.isValue()) {
|
|
|
switch (currentFieldName) {
|
|
|
case "index":
|
|
|
- index = parser.textOrNull();
|
|
|
+ index = parser.text();
|
|
|
break;
|
|
|
case "type":
|
|
|
type = parser.text();
|
|
@@ -159,9 +164,7 @@ public class TermsLookup implements Writeable, ToXContent {
|
|
|
|
|
|
@Override
|
|
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
|
|
- if (index != null) {
|
|
|
- builder.field("index", index);
|
|
|
- }
|
|
|
+ builder.field("index", index);
|
|
|
builder.field("type", type);
|
|
|
builder.field("id", id);
|
|
|
builder.field("path", path);
|