FuzzyLikeThisFieldQueryBuilder now defaults failOnUnsupportedField to true, to be consistent with REST API.

Closes #3374
This commit is contained in:
Boaz Leskes 2013-07-24 09:54:23 +02:00
parent b85bcde640
commit 497032e6e7
2 changed files with 3 additions and 6 deletions

View File

@ -38,7 +38,7 @@ public class FuzzyLikeThisFieldQueryBuilder extends BaseQueryBuilder implements
private Integer maxQueryTerms; private Integer maxQueryTerms;
private Boolean ignoreTF; private Boolean ignoreTF;
private String analyzer; private String analyzer;
private boolean failOnUnsupportedField; private boolean failOnUnsupportedField = true;
/** /**
* A fuzzy more like this query on the provided field. * A fuzzy more like this query on the provided field.

View File

@ -27,6 +27,7 @@ import org.testng.annotations.Test;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.index.query.QueryBuilders.fuzzyLikeThisFieldQuery; import static org.elasticsearch.index.query.QueryBuilders.fuzzyLikeThisFieldQuery;
import static org.elasticsearch.index.query.QueryBuilders.fuzzyLikeThisQuery; 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.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.testng.Assert.fail; import static org.testng.Assert.fail;
@ -74,11 +75,7 @@ public class FuzzyLikeThisActionTests extends AbstractSharedClusterTest {
assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L)); assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L));
// flt field query on a numeric field -> failure // flt field query on a numeric field -> failure
try { assertThrows(client().prepareSearch().setQuery(fuzzyLikeThisFieldQuery("int_value").likeText("42")), SearchPhaseExecutionException.class);
searchResponse = client().prepareSearch().setQuery(fuzzyLikeThisFieldQuery("int_value").likeText("42")).execute().actionGet();
} catch (SearchPhaseExecutionException e) {
// OK
}
// flt field query on a numeric field but fail_on_unsupported_field set to false // 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(); searchResponse = client().prepareSearch().setQuery(fuzzyLikeThisFieldQuery("int_value").likeText("42").failOnUnsupportedField(false)).execute().actionGet();