Skip to content

Commit 868e7f8

Browse files
author
Codehardt
committed
fix: replace elasticsearch characters in wildcard query
1 parent 6a3603a commit 868e7f8

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

export.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package evalostic
22

33
import (
44
"encoding/json"
5+
"strings"
56
)
67

78
// ExportElasticSearchQuery exports the compiled query into an ElasticSearch query, e.g.
@@ -27,13 +28,15 @@ func (e *Evalostic) ExportElasticSearchQueryMap(wildcardField string) map[string
2728
return query
2829
}
2930

31+
var wildcardReplacer = strings.NewReplacer("\\", "\\\\", "*", "\\*", "?", "\\?")
32+
3033
func (e *Evalostic) exportElasticSearchQuerySub(wildcardField string, indexToStrings map[int]string, entry decisionTreeEntry, node *decisionTreeNode) map[string]interface{} {
3134

3235
isLeaf := len(node.outputs) != 0
3336
wildcard := map[string]interface{}{
3437
"wildcard": map[string]interface{}{
3538
wildcardField: map[string]interface{}{
36-
"value": "*" + indexToStrings[entry.value] + "*",
39+
"value": "*" + wildcardReplacer.Replace(indexToStrings[entry.value]) + "*",
3740
"case_insensitive": entry.ci,
3841
},
3942
},

0 commit comments

Comments
 (0)