Skip to content

Commit

Permalink
Merge pull request #5 from rahul1193/rahul/rest-client-1.4.1
Browse files Browse the repository at this point in the history
support for es5 query changes for filtered, missing, nested, query fi…
  • Loading branch information
brandonkearby authored Jan 9, 2017
2 parents fddd928 + 70f4116 commit f1f29ad
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 30 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>1.4.1-rest-1.0.27-SNAPSHOT</version>
<version>1.4.1-rest-1.0.28-SNAPSHOT</version>
<packaging>jar</packaging>
<description>Elasticsearch - Open Source, Distributed, RESTful Search Engine</description>
<inceptionYear>2009</inceptionYear>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

package org.elasticsearch.index.query;

import org.elasticsearch.Version;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.xcontent.ToXContentUtils;
import org.elasticsearch.common.xcontent.XContentBuilder;

import java.io.IOException;
Expand Down Expand Up @@ -73,7 +75,11 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep
queryBuilder.toXContent(builder, params);
}
if (filterBuilder != null) {
builder.field("filter");
if (ToXContentUtils.getVersionFromParams(params).onOrAfter(Version.V_5_0_0)) {
builder.field("query");
} else {
builder.field("filter");
}
filterBuilder.toXContent(builder, params);
}
if (boost != -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package org.elasticsearch.index.query;

import org.elasticsearch.Version;
import org.elasticsearch.common.xcontent.ToXContentUtils;
import org.elasticsearch.common.xcontent.XContentBuilder;

import java.io.IOException;
Expand Down Expand Up @@ -68,17 +70,21 @@ public MissingFilterBuilder filterName(String filterName) {

@Override
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(MissingFilterParser.NAME);
builder.field("field", name);
if (nullValue != null) {
builder.field("null_value", nullValue);
if (ToXContentUtils.getVersionFromParams(params).onOrAfter(Version.V_5_0_0)) {
FilterBuilders.boolFilter().mustNot(FilterBuilders.existsFilter(name).filterName(filterName)).doXContent(builder, params);
} else {
builder.startObject(MissingFilterParser.NAME);
builder.field("field", name);
if (nullValue != null) {
builder.field("null_value", nullValue);
}
if (existence != null) {
builder.field("existence", existence);
}
if (filterName != null) {
builder.field("_name", filterName);
}
builder.endObject();
}
if (existence != null) {
builder.field("existence", existence);
}
if (filterName != null) {
builder.field("_name", filterName);
}
builder.endObject();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package org.elasticsearch.index.query;

import org.elasticsearch.Version;
import org.elasticsearch.common.xcontent.ToXContentUtils;
import org.elasticsearch.common.xcontent.XContentBuilder;

import java.io.IOException;
Expand Down Expand Up @@ -80,22 +82,29 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep
builder.field("query");
queryBuilder.toXContent(builder, params);
} else {
builder.field("filter");
if (ToXContentUtils.getVersionFromParams(params).onOrAfter(Version.V_5_0_0)) {
builder.field("query");
} else {
builder.field("filter");
}
filterBuilder.toXContent(builder, params);
}
if (join != null) {
builder.field("join", join);

if (!ToXContentUtils.getVersionFromParams(params).onOrAfter(Version.V_5_0_0)) {
if (join != null) {
builder.field("join", join);
}
if (cache != null) {
builder.field("_cache", cache);
}
if (cacheKey != null) {
builder.field("_cache_key", cacheKey);
}
if (filterName != null) {
builder.field("_name", filterName);
}
}
builder.field("path", path);
if (filterName != null) {
builder.field("_name", filterName);
}
if (cache != null) {
builder.field("_cache", cache);
}
if (cacheKey != null) {
builder.field("_cache_key", cacheKey);
}
builder.endObject();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package org.elasticsearch.index.query;

import org.elasticsearch.Version;
import org.elasticsearch.common.xcontent.ToXContentUtils;
import org.elasticsearch.common.xcontent.XContentBuilder;

import java.io.IOException;
Expand Down Expand Up @@ -80,7 +82,11 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep
builder.field("query");
queryBuilder.toXContent(builder, params);
} else {
builder.field("filter");
if (ToXContentUtils.getVersionFromParams(params).onOrAfter(Version.V_5_0_0)) {
builder.field("query");
} else {
builder.field("filter");
}
filterBuilder.toXContent(builder, params);
}
builder.field("path", path);
Expand All @@ -90,8 +96,10 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep
if (boost != 1.0f) {
builder.field("boost", boost);
}
if (queryName != null) {
builder.field("_name", queryName);
if (!ToXContentUtils.getVersionFromParams(params).onOrAfter(Version.V_5_0_0)) {
if (queryName != null) {
builder.field("_name", queryName);
}
}
builder.endObject();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

package org.elasticsearch.index.query;

import org.elasticsearch.Version;
import org.elasticsearch.common.xcontent.ToXContentUtils;
import org.elasticsearch.common.xcontent.XContentBuilder;

import java.io.IOException;

/**
* A filter that simply wraps a query.
*
*
*/
public class QueryFilterBuilder extends BaseFilterBuilder {

Expand Down Expand Up @@ -66,6 +66,8 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep
if (filterName == null && cache == null) {
builder.field(QueryFilterParser.NAME);
queryBuilder.toXContent(builder, params);
} else if (ToXContentUtils.getVersionFromParams(params).onOrAfter(Version.V_5_0_0)) {
queryBuilder.toXContent(builder, params);
} else {
builder.startObject(FQueryFilterParser.NAME);
builder.field("query");
Expand Down

0 comments on commit f1f29ad

Please sign in to comment.