From ec421974b960854609f4f0d0b131a88f9f177a6e Mon Sep 17 00:00:00 2001 From: Nilabh Sagar Date: Thu, 13 Apr 2017 12:13:29 +0530 Subject: Allow different data types for category in Context suggester (#23491) The "category" in context suggester could be String, Number or Boolean. However with the changes in version 5 this is failing and only accepting String. This will have problem for existing users of Elasticsearch if they choose to migrate to higher version; as their existing Mapping and query will fail as mentioned in a bug #22358 This PR fixes the above mentioned issue and allows user to migrate seamlessly. Closes #22358 --- .../suggest/completion/context/CategoryContextMapping.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryContextMapping.java') diff --git a/core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryContextMapping.java b/core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryContextMapping.java index 150b7bf4f9..38e31ec92a 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryContextMapping.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryContextMapping.java @@ -107,21 +107,24 @@ public class CategoryContextMapping extends ContextMapping * */ @Override - public Set parseContext(ParseContext parseContext, XContentParser parser) throws IOException, ElasticsearchParseException { + public Set parseContext(ParseContext parseContext, XContentParser parser) + throws IOException, ElasticsearchParseException { final Set contexts = new HashSet<>(); Token token = parser.currentToken(); - if (token == Token.VALUE_STRING) { + if (token == Token.VALUE_STRING || token == Token.VALUE_NUMBER || token == Token.VALUE_BOOLEAN) { contexts.add(parser.text()); } else if (token == Token.START_ARRAY) { while ((token = parser.nextToken()) != Token.END_ARRAY) { - if (token == Token.VALUE_STRING) { + if (token == Token.VALUE_STRING || token == Token.VALUE_NUMBER || token == Token.VALUE_BOOLEAN) { contexts.add(parser.text()); } else { - throw new ElasticsearchParseException("context array must have string values"); + throw new ElasticsearchParseException( + "context array must have string, number or boolean values, but was [" + token + "]"); } } } else { - throw new ElasticsearchParseException("contexts must be a string or a list of strings"); + throw new ElasticsearchParseException( + "contexts must be a string, number or boolean or a list of string, number or boolean, but was [" + token + "]"); } return contexts; } -- cgit v1.2.3