summaryrefslogtreecommitdiff
path: root/core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryContextMapping.java
diff options
context:
space:
mode:
authorNilabh Sagar <nilabhsagar@gmail.com>2017-04-13 12:13:29 +0530
committerRyan Ernst <ryan@iernst.net>2017-04-12 23:43:29 -0700
commitec421974b960854609f4f0d0b131a88f9f177a6e (patch)
tree78c682bb21f538abb52fd14ec0d1923a6d87f53f /core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryContextMapping.java
parentc19044ddf6a8ed421d75fdb3db6bb02b06350b8f (diff)
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
Diffstat (limited to 'core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryContextMapping.java')
-rw-r--r--core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryContextMapping.java13
1 files changed, 8 insertions, 5 deletions
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<CategoryQueryContext>
* </ul>
*/
@Override
- public Set<CharSequence> parseContext(ParseContext parseContext, XContentParser parser) throws IOException, ElasticsearchParseException {
+ public Set<CharSequence> parseContext(ParseContext parseContext, XContentParser parser)
+ throws IOException, ElasticsearchParseException {
final Set<CharSequence> 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;
}