Skip to content

Commit 8da7611

Browse files
committed
Fix a validation bug in put synonym rule
1 parent 3b8bbfd commit 8da7611

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/synonyms/50_synonym_rule_put.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,69 @@ setup:
7979
rule_id: "test-id-0"
8080
body:
8181
synonyms: "i-phone, iphone"
82+
83+
---
84+
"Timeout can be specified":
85+
- do:
86+
synonyms.put_synonym_rule:
87+
set_id: "test-synonyms"
88+
rule_id: "test-id-0"
89+
timeout: 10s
90+
body:
91+
synonyms: "i-phone, iphone"
92+
93+
- match: { result: "created" }
94+
- match: { reload_analyzers_details._shards.total: 0 }
95+
- length: { reload_analyzers_details.reload_details: 0 }
96+
97+
---
98+
"Validation failure tests":
99+
- do:
100+
catch: /\[synonyms\] field can't be empty/
101+
synonyms.put_synonym_rule:
102+
set_id: "test-synonyms"
103+
rule_id: "test-id-0"
104+
body:
105+
synonyms: ""
106+
107+
- do:
108+
catch: /More than one explicit mapping specified in the same synonyms rule/
109+
synonyms.put_synonym_rule:
110+
set_id: "test-synonyms"
111+
rule_id: "test-id-0"
112+
body:
113+
synonyms: "bye => => goodbye"
114+
115+
- do:
116+
catch: /Incorrect syntax for \[synonyms\]/
117+
synonyms.put_synonym_rule:
118+
set_id: "test-synonyms"
119+
rule_id: "test-id-0"
120+
body:
121+
synonyms: " => goodbye"
122+
123+
- do:
124+
catch: /Incorrect syntax for \[synonyms\]/
125+
synonyms.put_synonym_rule:
126+
set_id: "test-synonyms"
127+
rule_id: "test-id-0"
128+
body:
129+
synonyms: "bye => "
130+
131+
- do:
132+
catch: /Incorrect syntax for \[synonyms\]/
133+
synonyms.put_synonym_rule:
134+
set_id: "test-synonyms"
135+
rule_id: "test-id-0"
136+
body:
137+
synonyms: "bye, goodbye, "
138+
139+
- do:
140+
catch: /as a time value:\ negative durations are not supported/
141+
synonyms.put_synonym_rule:
142+
set_id: "test-synonyms"
143+
rule_id: "test-id-0"
144+
timeout: -100s
145+
body:
146+
synonyms_set:
147+
- synonyms: "bye, goodbye"

server/src/main/java/org/elasticsearch/action/synonyms/PutSynonymRuleAction.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ public ActionRequestValidationException validate() {
9797
if (Strings.isNullOrEmpty(synonymRule.id())) {
9898
validationException = ValidateActions.addValidationError("synonym rule id must be specified", validationException);
9999
}
100+
String error = synonymRule.validate();
101+
if (error != null) {
102+
validationException = ValidateActions.addValidationError(error, validationException);
103+
}
100104

101105
return validationException;
102106
}

0 commit comments

Comments
 (0)