FuzzLikeThis*QueryBuilder and MoreLikeThis*QueryBuilder do not send failOnUnsupportedField if not explicitly specified.
Closes #3402 , a better solution to #3374
This commit is contained in:
parent
7fd54acd66
commit
e0e6a58357
|
@ -38,7 +38,7 @@ public class FuzzyLikeThisFieldQueryBuilder extends BaseQueryBuilder implements
|
|||
private Integer maxQueryTerms;
|
||||
private Boolean ignoreTF;
|
||||
private String analyzer;
|
||||
private boolean failOnUnsupportedField = true;
|
||||
private Boolean failOnUnsupportedField;
|
||||
|
||||
/**
|
||||
* A fuzzy more like this query on the provided field.
|
||||
|
@ -124,7 +124,7 @@ public class FuzzyLikeThisFieldQueryBuilder extends BaseQueryBuilder implements
|
|||
if (analyzer != null) {
|
||||
builder.field("analyzer", analyzer);
|
||||
}
|
||||
if (!failOnUnsupportedField) {
|
||||
if (failOnUnsupportedField != null) {
|
||||
builder.field("fail_on_unsupported_field", failOnUnsupportedField);
|
||||
}
|
||||
builder.endObject();
|
||||
|
|
|
@ -38,7 +38,7 @@ public class FuzzyLikeThisQueryBuilder extends BaseQueryBuilder implements Boost
|
|||
private Integer maxQueryTerms;
|
||||
private Boolean ignoreTF;
|
||||
private String analyzer;
|
||||
private boolean failOnUnsupportedField = true;;
|
||||
private Boolean failOnUnsupportedField;
|
||||
|
||||
/**
|
||||
* Constructs a new fuzzy like this query which uses the "_all" field.
|
||||
|
@ -137,7 +137,7 @@ public class FuzzyLikeThisQueryBuilder extends BaseQueryBuilder implements Boost
|
|||
if (analyzer != null) {
|
||||
builder.field("analyzer", analyzer);
|
||||
}
|
||||
if (!failOnUnsupportedField) {
|
||||
if (failOnUnsupportedField != null) {
|
||||
builder.field("fail_on_unsupported_field", failOnUnsupportedField);
|
||||
}
|
||||
builder.endObject();
|
||||
|
|
|
@ -25,8 +25,6 @@ import java.io.IOException;
|
|||
|
||||
/**
|
||||
* A more like this query that runs against a specific field.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class MoreLikeThisFieldQueryBuilder extends BaseQueryBuilder implements BoostableQueryBuilder<MoreLikeThisFieldQueryBuilder> {
|
||||
|
||||
|
@ -44,7 +42,7 @@ public class MoreLikeThisFieldQueryBuilder extends BaseQueryBuilder implements B
|
|||
private float boostTerms = -1;
|
||||
private float boost = -1;
|
||||
private String analyzer;
|
||||
private boolean failOnUnsupportedField;
|
||||
private Boolean failOnUnsupportedField;
|
||||
|
||||
/**
|
||||
* A more like this query that runs against a specific field.
|
||||
|
@ -211,7 +209,7 @@ public class MoreLikeThisFieldQueryBuilder extends BaseQueryBuilder implements B
|
|||
if (analyzer != null) {
|
||||
builder.field("analyzer", analyzer);
|
||||
}
|
||||
if (!failOnUnsupportedField) {
|
||||
if (failOnUnsupportedField != null) {
|
||||
builder.field("fail_on_unsupported_field", failOnUnsupportedField);
|
||||
}
|
||||
builder.endObject();
|
||||
|
|
|
@ -26,8 +26,6 @@ import java.io.IOException;
|
|||
/**
|
||||
* A more like this query that finds documents that are "like" the provided {@link #likeText(String)}
|
||||
* which is checked against the fields the query is constructed with.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class MoreLikeThisQueryBuilder extends BaseQueryBuilder implements BoostableQueryBuilder<MoreLikeThisQueryBuilder> {
|
||||
|
||||
|
@ -45,7 +43,7 @@ public class MoreLikeThisQueryBuilder extends BaseQueryBuilder implements Boosta
|
|||
private float boostTerms = -1;
|
||||
private float boost = -1;
|
||||
private String analyzer;
|
||||
private boolean failOnUnsupportedField = true;
|
||||
private Boolean failOnUnsupportedField;
|
||||
|
||||
/**
|
||||
* Constructs a new more like this query which uses the "_all" field.
|
||||
|
@ -225,7 +223,7 @@ public class MoreLikeThisQueryBuilder extends BaseQueryBuilder implements Boosta
|
|||
if (analyzer != null) {
|
||||
builder.field("analyzer", analyzer);
|
||||
}
|
||||
if (!failOnUnsupportedField) {
|
||||
if (failOnUnsupportedField != null) {
|
||||
builder.field("fail_on_unsupported_field", failOnUnsupportedField);
|
||||
}
|
||||
builder.endObject();
|
||||
|
|
|
@ -28,9 +28,7 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
|||
import static org.elasticsearch.index.query.QueryBuilders.fuzzyLikeThisFieldQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.fuzzyLikeThisQuery;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -61,22 +59,24 @@ public class FuzzyLikeThisActionTests extends AbstractSharedClusterTest {
|
|||
assertThat(searchResponse.getFailedShards(), equalTo(0));
|
||||
assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L));
|
||||
|
||||
// flt query with at least a numeric field -> fail
|
||||
try {
|
||||
searchResponse = client().prepareSearch().setQuery(fuzzyLikeThisQuery("string_value", "int_value").likeText("index")).execute().actionGet();
|
||||
fail();
|
||||
} catch (SearchPhaseExecutionException e) {
|
||||
// OK
|
||||
}
|
||||
// flt query with at least a numeric field -> fail by default
|
||||
assertThrows(client().prepareSearch().setQuery(fuzzyLikeThisQuery("string_value", "int_value").likeText("index")), SearchPhaseExecutionException.class);
|
||||
|
||||
// flt query with at least a numeric field -> fail by command
|
||||
assertThrows(client().prepareSearch().setQuery(fuzzyLikeThisQuery("string_value", "int_value").likeText("index").failOnUnsupportedField(true)), SearchPhaseExecutionException.class);
|
||||
|
||||
|
||||
// flt query with at least a numeric field but fail_on_unsupported_field set to false
|
||||
searchResponse = client().prepareSearch().setQuery(fuzzyLikeThisQuery("string_value", "int_value").likeText("index").failOnUnsupportedField(false)).execute().actionGet();
|
||||
assertThat(searchResponse.getFailedShards(), equalTo(0));
|
||||
assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L));
|
||||
|
||||
// flt field query on a numeric field -> failure
|
||||
// flt field query on a numeric field -> failure by default
|
||||
assertThrows(client().prepareSearch().setQuery(fuzzyLikeThisFieldQuery("int_value").likeText("42")), SearchPhaseExecutionException.class);
|
||||
|
||||
// flt field query on a numeric field -> failure by command
|
||||
assertThrows(client().prepareSearch().setQuery(fuzzyLikeThisFieldQuery("int_value").likeText("42").failOnUnsupportedField(true)), SearchPhaseExecutionException.class);
|
||||
|
||||
// flt field query on a numeric field but fail_on_unsupported_field set to false
|
||||
searchResponse = client().prepareSearch().setQuery(fuzzyLikeThisFieldQuery("int_value").likeText("42").failOnUnsupportedField(false)).execute().actionGet();
|
||||
assertThat(searchResponse.getFailedShards(), equalTo(0));
|
||||
|
|
|
@ -33,10 +33,9 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
|||
import static org.elasticsearch.index.query.FilterBuilders.termFilter;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.moreLikeThisFieldQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.moreLikeThisQuery;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -172,12 +171,7 @@ public class MoreLikeThisActionTests extends AbstractSharedClusterTest {
|
|||
assertThat(searchResponse.getHits().totalHits(), equalTo(1L));
|
||||
|
||||
// Explicit list of fields including numeric fields -> fail
|
||||
try {
|
||||
searchResponse = client().prepareMoreLikeThis("test", "type", "1").setField("string_value", "int_value").execute().actionGet();
|
||||
fail();
|
||||
} catch (SearchPhaseExecutionException e) {
|
||||
// OK
|
||||
}
|
||||
assertThrows(client().prepareMoreLikeThis("test", "type", "1").setField("string_value", "int_value"), SearchPhaseExecutionException.class);
|
||||
|
||||
// mlt query with no field -> OK
|
||||
searchResponse = client().prepareSearch().setQuery(moreLikeThisQuery().likeText("index").minTermFreq(1).minDocFreq(1)).execute().actionGet();
|
||||
|
@ -189,25 +183,24 @@ public class MoreLikeThisActionTests extends AbstractSharedClusterTest {
|
|||
assertThat(searchResponse.getFailedShards(), equalTo(0));
|
||||
assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L));
|
||||
|
||||
// mlt query with at least a numeric field -> fail
|
||||
try {
|
||||
searchResponse = client().prepareSearch().setQuery(moreLikeThisQuery("string_value", "int_value").likeText("index")).execute().actionGet();
|
||||
fail();
|
||||
} catch (SearchPhaseExecutionException e) {
|
||||
// OK
|
||||
}
|
||||
// mlt query with at least a numeric field -> fail by default
|
||||
assertThrows(client().prepareSearch().setQuery(moreLikeThisQuery("string_value", "int_value").likeText("index")), SearchPhaseExecutionException.class);
|
||||
|
||||
// mlt query with at least a numeric field -> fail by command
|
||||
assertThrows(client().prepareSearch().setQuery(moreLikeThisQuery("string_value", "int_value").likeText("index").failOnUnsupportedField(true)), SearchPhaseExecutionException.class);
|
||||
|
||||
|
||||
// mlt query with at least a numeric field but fail_on_unsupported_field set to false
|
||||
searchResponse = client().prepareSearch().setQuery(moreLikeThisQuery("string_value", "int_value").likeText("index").minTermFreq(1).minDocFreq(1).failOnUnsupportedField(false)).execute().actionGet();
|
||||
searchResponse = client().prepareSearch().setQuery(moreLikeThisQuery("string_value", "int_value").likeText("index").minTermFreq(1).minDocFreq(1).failOnUnsupportedField(false)).get();
|
||||
assertThat(searchResponse.getFailedShards(), equalTo(0));
|
||||
assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L));
|
||||
|
||||
// mlt field query on a numeric field -> failure
|
||||
try {
|
||||
searchResponse = client().prepareSearch().setQuery(moreLikeThisFieldQuery("int_value").likeText("42").minTermFreq(1).minDocFreq(1)).execute().actionGet();
|
||||
} catch (SearchPhaseExecutionException e) {
|
||||
// OK
|
||||
}
|
||||
// mlt field query on a numeric field -> failure by default
|
||||
assertThrows(client().prepareSearch().setQuery(moreLikeThisFieldQuery("int_value").likeText("42").minTermFreq(1).minDocFreq(1)), SearchPhaseExecutionException.class);
|
||||
|
||||
// mlt field query on a numeric field -> failure by command
|
||||
assertThrows(client().prepareSearch().setQuery(moreLikeThisFieldQuery("int_value").likeText("42").minTermFreq(1).minDocFreq(1).failOnUnsupportedField(true)),
|
||||
SearchPhaseExecutionException.class);
|
||||
|
||||
// mlt field query on a numeric field but fail_on_unsupported_field set to false
|
||||
searchResponse = client().prepareSearch().setQuery(moreLikeThisFieldQuery("int_value").likeText("42").minTermFreq(1).minDocFreq(1).failOnUnsupportedField(false)).execute().actionGet();
|
||||
|
|
Loading…
Reference in New Issue