Skip to content

Commit

Permalink
Allow non-exact query types on the root JSON field. (#41290)
Browse files Browse the repository at this point in the history
In an earlier iteration of the design, it made sense to disallow these query
types on the root JSON field. It should now it be fine to allow them.
  • Loading branch information
jtibshirani committed May 29, 2019
1 parent 2b71ed8 commit bf5c457
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,23 +315,23 @@ public Query rangeQuery(Object lowerTerm,
@Override
public Query fuzzyQuery(Object value, Fuzziness fuzziness, int prefixLength, int maxExpansions,
boolean transpositions) {
throw new UnsupportedOperationException("[fuzzy] queries are not currently supported on [" +
CONTENT_TYPE + "] fields.");
throw new UnsupportedOperationException("[fuzzy] queries are not currently supported on keyed " +
"[" + CONTENT_TYPE + "] fields.");
}

@Override
public Query regexpQuery(String value, int flags, int maxDeterminizedStates,
MultiTermQuery.RewriteMethod method, QueryShardContext context) {
throw new UnsupportedOperationException("[regexp] queries are not currently supported on [" +
CONTENT_TYPE + "] fields.");
throw new UnsupportedOperationException("[regexp] queries are not currently supported on keyed " +
"[" + CONTENT_TYPE + "] fields.");
}

@Override
public Query wildcardQuery(String value,
MultiTermQuery.RewriteMethod method,
QueryShardContext context) {
throw new UnsupportedOperationException("[wildcard] queries are not currently supported on [" +
CONTENT_TYPE + "] fields.");
throw new UnsupportedOperationException("[wildcard] queries are not currently supported on keyed " +
"[" + CONTENT_TYPE + "] fields.");
}

@Override
Expand Down Expand Up @@ -521,28 +521,6 @@ public Query existsQuery(QueryShardContext context) {
}
}

@Override
public Query fuzzyQuery(Object value, Fuzziness fuzziness, int prefixLength, int maxExpansions,
boolean transpositions) {
throw new UnsupportedOperationException("[fuzzy] queries are not currently supported on [" +
CONTENT_TYPE + "] fields.");
}

@Override
public Query regexpQuery(String value, int flags, int maxDeterminizedStates,
MultiTermQuery.RewriteMethod method, QueryShardContext context) {
throw new UnsupportedOperationException("[regexp] queries are not currently supported on [" +
CONTENT_TYPE + "] fields.");
}

@Override
public Query wildcardQuery(String value,
MultiTermQuery.RewriteMethod method,
QueryShardContext context) {
throw new UnsupportedOperationException("[wildcard] queries are not currently supported on [" +
CONTENT_TYPE + "] fields.");
}

@Override
public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName) {
failIfNoDocValues();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void testFuzzyQuery() {

UnsupportedOperationException e = expectThrows(UnsupportedOperationException.class,
() -> ft.fuzzyQuery("valuee", Fuzziness.fromEdits(2), 1, 50, true));
assertEquals("[fuzzy] queries are not currently supported on [embedded_json] fields.", e.getMessage());
assertEquals("[fuzzy] queries are not currently supported on keyed [embedded_json] fields.", e.getMessage());
}

public void testRangeQuery() {
Expand Down Expand Up @@ -151,7 +151,7 @@ public void testRegexpQuery() {

UnsupportedOperationException e = expectThrows(UnsupportedOperationException.class,
() -> ft.regexpQuery("valu*", 0, 10, null, null));
assertEquals("[regexp] queries are not currently supported on [embedded_json] fields.", e.getMessage());
assertEquals("[regexp] queries are not currently supported on keyed [embedded_json] fields.", e.getMessage());
}

public void testWildcardQuery() {
Expand All @@ -160,6 +160,6 @@ public void testWildcardQuery() {

UnsupportedOperationException e = expectThrows(UnsupportedOperationException.class,
() -> ft.wildcardQuery("valu*", null, null));
assertEquals("[wildcard] queries are not currently supported on [embedded_json] fields.", e.getMessage());
assertEquals("[wildcard] queries are not currently supported on keyed [embedded_json] fields.", e.getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
import org.apache.lucene.index.IndexOptions;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.DocValuesFieldExistsQuery;
import org.apache.lucene.search.FuzzyQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.RegexpQuery;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TermRangeQuery;
import org.apache.lucene.search.WildcardQuery;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.unit.Fuzziness;
import org.elasticsearch.index.mapper.JsonFieldMapper.RootJsonFieldType;
Expand Down Expand Up @@ -83,9 +86,9 @@ public void testFuzzyQuery() {
RootJsonFieldType ft = createDefaultFieldType();
ft.setName("field");

UnsupportedOperationException e = expectThrows(UnsupportedOperationException.class,
() -> ft.fuzzyQuery("valuee", Fuzziness.fromEdits(2), 1, 50, true));
assertEquals("[fuzzy] queries are not currently supported on [embedded_json] fields.", e.getMessage());
Query expected = new FuzzyQuery(new Term("field", "value"), 2, 1, 50, true);
Query actual = ft.fuzzyQuery("value", Fuzziness.fromEdits(2), 1, 50, true);
assertEquals(expected, actual);
}

public void testRangeQuery() {
Expand All @@ -107,17 +110,16 @@ public void testRegexpQuery() {
RootJsonFieldType ft = createDefaultFieldType();
ft.setName("field");

UnsupportedOperationException e = expectThrows(UnsupportedOperationException.class,
() -> ft.regexpQuery("valu*", 0, 10, null, null));
assertEquals("[regexp] queries are not currently supported on [embedded_json] fields.", e.getMessage());
Query expected = new RegexpQuery(new Term("field", "val.*"));
Query actual = ft.regexpQuery("val.*", 0, 10, null, null);
assertEquals(expected, actual);
}

public void testWildcardQuery() {
RootJsonFieldType ft = createDefaultFieldType();
ft.setName("field");

UnsupportedOperationException e = expectThrows(UnsupportedOperationException.class,
() -> ft.wildcardQuery("valu*", null, null));
assertEquals("[wildcard] queries are not currently supported on [embedded_json] fields.", e.getMessage());
Query expected = new WildcardQuery(new Term("field", new BytesRef("valu*")));
assertEquals(expected, ft.wildcardQuery("valu*", null, null));
}
}

0 comments on commit bf5c457

Please sign in to comment.