diff --git a/core/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java index 7be77795e82..c0d8be286b4 100644 --- a/core/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java @@ -229,6 +229,10 @@ public class RegexpQueryBuilder extends AbstractQueryBuilder if (parseContext.getParseFieldMatcher().match(currentFieldName, NAME_FIELD)) { queryName = parser.text(); } else { + if (fieldName != null) { + throw new ParsingException(parser.getTokenLocation(), "[regexp] query doesn't support multiple fields, found [" + + fieldName + "] and [" + parser.currentName() + "]"); + } fieldName = currentFieldName; value = parser.textOrNull(); } diff --git a/core/src/test/java/org/elasticsearch/index/query/RegexpQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/RegexpQueryBuilderTests.java index 41cfc2c63ff..7daed416a05 100644 --- a/core/src/test/java/org/elasticsearch/index/query/RegexpQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/RegexpQueryBuilderTests.java @@ -135,5 +135,15 @@ public class RegexpQueryBuilderTests extends AbstractQueryTestCase parseQuery(json)); assertEquals("[regexp] query doesn't support multiple fields, found [user1] and [user2]", e.getMessage()); + + String shortJson = + "{\n" + + " \"regexp\": {\n" + + " \"user1\": \"k.*y\",\n" + + " \"user2\": \"k.*y\"\n" + + " }\n" + + "}"; + e = expectThrows(ParsingException.class, () -> parseQuery(shortJson)); + assertEquals("[regexp] query doesn't support multiple fields, found [user1] and [user2]", e.getMessage()); } }