Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow non-exact query types on the root JSON field. #41290

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what is your plan on this but it should be possible to allow this type of query by adding the field prefix in the fuzzy query and change the prefixLength to be prefixLength + field.length + 1 ?

}

@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.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, just adding the field prefix should work ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it'd make sense to automatically adjust maxDeterminizedStates as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's keep the value as is, the field name shouldn't consume a lot of states and the current limit is already high (10,000).

}

@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.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here ?

}

@Override
Expand Down Expand Up @@ -517,28 +517,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));
}
}