Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3ee80ee

Browse files
committedJun 9, 2024··
Add YAML REST tests and fix query normalization
Signed-off-by: Michael Froh <froh@amazon.com>
1 parent c69d8f5 commit 3ee80ee

File tree

2 files changed

+212
-0
lines changed

2 files changed

+212
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
setup:
2+
- skip:
3+
version: " - 2.99.99"
4+
reason: "Added in 2.15, but need to skip pre-3.0 before backport"
5+
6+
- do:
7+
indices.create:
8+
index: test
9+
body:
10+
mappings:
11+
properties:
12+
my_field:
13+
type: wildcard
14+
fields:
15+
lower:
16+
type: wildcard
17+
normalizer: lowercase
18+
doc_values:
19+
type: wildcard
20+
doc_values: true
21+
22+
- do:
23+
index:
24+
index: test
25+
id: 1
26+
body:
27+
my_field: "org.opensearch.transport.NodeDisconnectedException: [node_s0][127.0.0.1:39953][disconnected] disconnected"
28+
- do:
29+
index:
30+
index: test
31+
id: 2
32+
body:
33+
my_field: "[2024-06-08T06:31:37,443][INFO ][o.o.c.c.Coordinator ] [node_s2] cluster-manager node [{node_s0}{Nj7FjR7hRP2lh_zur8KN_g}{OTGOoWmmSsWP_RQ3tIKJ9g}{127.0.0.1}{127.0.0.1:39953}{imr}{shard_indexing_pressure_enabled=true}] failed, restarting discovery"
34+
35+
- do:
36+
index:
37+
index: test
38+
id: 3
39+
body:
40+
my_field: "[2024-06-08T06:31:37,451][INFO ][o.o.c.s.ClusterApplierService] [node_s2] cluster-manager node changed {previous [{node_s0}{Nj7FjR7hRP2lh_zur8KN_g}{OTGOoWmmSsWP_RQ3tIKJ9g}{127.0.0.1}{127.0.0.1:39953}{imr}{shard_indexing_pressure_enabled=true}], current []}, term: 1, version: 24, reason: becoming candidate: onLeaderFailure"
41+
- do:
42+
index:
43+
index: test
44+
id: 4
45+
body:
46+
my_field: "[2024-06-08T06:31:37,452][WARN ][o.o.c.NodeConnectionsService] [node_s1] failed to connect to {node_s0}{Nj7FjR7hRP2lh_zur8KN_g}{OTGOoWmmSsWP_RQ3tIKJ9g}{127.0.0.1}{127.0.0.1:39953}{imr}{shard_indexing_pressure_enabled=true} (tried [1] times)"
47+
- do:
48+
index:
49+
index: test
50+
id: 5
51+
body:
52+
my_field: "AbCd"
53+
- do:
54+
indices.refresh: {}
55+
56+
---
57+
"term query matches exact value":
58+
- do:
59+
search:
60+
index: test
61+
body:
62+
query:
63+
term:
64+
my_field: "AbCd"
65+
- match: { hits.total.value: 1 }
66+
- match: { hits.hits.0._id: "5" }
67+
68+
- do:
69+
search:
70+
index: test
71+
body:
72+
query:
73+
term:
74+
my_field.doc_values: "AbCd"
75+
- match: { hits.total.value: 1 }
76+
- match: { hits.hits.0._id: "5" }
77+
78+
---
79+
"term query matches lowercase-normalized value":
80+
- do:
81+
search:
82+
index: test
83+
body:
84+
query:
85+
term:
86+
my_field.lower: "abcd"
87+
- match: { hits.total.value: 1 }
88+
- match: { hits.hits.0._id: "5" }
89+
90+
- do:
91+
search:
92+
index: test
93+
body:
94+
query:
95+
term:
96+
my_field.lower: "ABCD"
97+
- match: { hits.total.value: 1 }
98+
- match: { hits.hits.0._id: "5" }
99+
100+
- do:
101+
search:
102+
index: test
103+
body:
104+
query:
105+
term:
106+
my_field: "abcd"
107+
- match: { hits.total.value: 0 }
108+
109+
---
110+
"wildcard query matches":
111+
- do:
112+
search:
113+
index: test
114+
body:
115+
query:
116+
wildcard:
117+
my_field:
118+
value: "*Node*Exception*"
119+
- match: { hits.total.value: 1 }
120+
- match: { hits.hits.0._id: "1" }
121+
122+
---
123+
"wildcard query matches lowercase-normalized field":
124+
- do:
125+
search:
126+
index: test
127+
body:
128+
query:
129+
wildcard:
130+
my_field.lower:
131+
value: "*node*exception*"
132+
- match: { hits.total.value: 1 }
133+
- match: { hits.hits.0._id: "1" }
134+
135+
- do:
136+
search:
137+
index: test
138+
body:
139+
query:
140+
wildcard:
141+
my_field.lower:
142+
value: "*NODE*EXCEPTION*"
143+
- match: { hits.total.value: 1 }
144+
- match: { hits.hits.0._id: "1" }
145+
146+
- do:
147+
search:
148+
index: test
149+
body:
150+
query:
151+
wildcard:
152+
my_field:
153+
value: "*node*exception*"
154+
- match: { hits.total.value: 0 }
155+
156+
---
157+
"prefix query matches":
158+
- do:
159+
search:
160+
index: test
161+
body:
162+
query:
163+
prefix:
164+
my_field:
165+
value: "[2024-06-08T"
166+
- match: { hits.total.value: 3 }
167+
168+
---
169+
"regexp query matches":
170+
- do:
171+
search:
172+
index: test
173+
body:
174+
query:
175+
regexp:
176+
my_field:
177+
value: ".*06-08.*cluster-manager node.*"
178+
- match: { hits.total.value: 2 }
179+
180+
---
181+
"regexp query matches lowercase-normalized field":
182+
- do:
183+
search:
184+
index: test
185+
body:
186+
query:
187+
regexp:
188+
my_field.lower:
189+
value: ".*06-08.*Cluster-Manager Node.*"
190+
- match: { hits.total.value: 2 }
191+
192+
- do:
193+
search:
194+
index: test
195+
body:
196+
query:
197+
regexp:
198+
my_field:
199+
value: ".*06-08.*Cluster-Manager Node.*"
200+
- match: { hits.total.value: 0 }

‎server/src/main/java/org/opensearch/index/mapper/WildcardFieldMapper.java

+12
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,10 @@ public Query prefixQuery(String value, MultiTermQuery.RewriteMethod method, bool
417417

418418
@Override
419419
public Query wildcardQuery(String value, MultiTermQuery.RewriteMethod method, boolean caseInsensitive, QueryShardContext context) {
420+
NamedAnalyzer normalizer = normalizer();
421+
if (normalizer != null) {
422+
value = normalizeWildcardPattern(name(), value, normalizer);
423+
}
420424
final String finalValue;
421425
if (caseInsensitive) {
422426
// Use ROOT locale, as it seems to be consistent with AutomatonQueries.toCaseInsensitiveChar.
@@ -429,6 +433,9 @@ public Query wildcardQuery(String value, MultiTermQuery.RewriteMethod method, bo
429433
Automaton automaton = WildcardQuery.toAutomaton(new Term(name(), finalValue));
430434
CompiledAutomaton compiledAutomaton = new CompiledAutomaton(automaton);
431435
matchPredicate = s -> {
436+
if (caseInsensitive) {
437+
s = s.toLowerCase(Locale.ROOT);
438+
}
432439
BytesRef valueBytes = BytesRefs.toBytesRef(s);
433440
return compiledAutomaton.runAutomaton.run(valueBytes.bytes, valueBytes.offset, valueBytes.length);
434441
};
@@ -524,6 +531,11 @@ public Query regexpQuery(
524531
MultiTermQuery.RewriteMethod method,
525532
QueryShardContext context
526533
) {
534+
NamedAnalyzer normalizer = normalizer();
535+
if (normalizer != null) {
536+
value = normalizer.normalize(name(), value).utf8ToString();
537+
}
538+
527539
RegExp regExp = new RegExp(value, syntaxFlags, matchFlags);
528540
Automaton automaton = regExp.toAutomaton(maxDeterminizedStates);
529541
CompiledAutomaton compiledAutomaton = new CompiledAutomaton(automaton);

0 commit comments

Comments
 (0)
Please sign in to comment.