Skip to content

Commit

Permalink
add test for analyzer validilty on derived field
Browse files Browse the repository at this point in the history
Signed-off-by: Rishabh Maurya <rishabhmaurya05@gmail.com>
  • Loading branch information
rishabhmaurya committed May 16, 2024
1 parent c262f17 commit 4ffd4d5
Showing 1 changed file with 105 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
---
"Test default index analyzer simple is applied on derived fields":
- do:
indices.create:
index: test
body:
settings:
index.analysis.analyzer.default.type: simple
mappings:
properties:
text:
type: text
json_field:
type: text
derived:
derived_text:
type: text
script: "emit(params._source[\"text\"])"
derived_object:
type: object
properties:
array_of_text: text
script: "emit(params._source[\"json_field\"])"
source_indexed_field: "json_field"

- do:
index:
index: test
id: 1
body: {
text: "Email: example@example.com, Visit https://example.com for more info.",
json_field: "{\"array_of_text\": [\"Email: example@example.com, Visit https://example.com for more info.\", \"Email: example@example.com, Visit https://example.com for more info.\"]}}"
}

- do:
indices.refresh:
index: [test]
- do:
search:
index: test
q: "derived_text:example.com"
analyzer: standard

- match: { hits.total.value: 0 }

- do:
search:
index: test
q: "derived_text:example.com"
analyzer: simple

- match: { hits.total.value: 1 }

---
"Test default index analyzer standard is applied on derived fields":
- do:
indices.create:
index: test
body:
settings:
index.analysis.analyzer.default.type: standard
mappings:
properties:
text:
type: text
json_field:
type: text
derived:
derived_text:
type: text
script: "emit(params._source[\"text\"])"
derived_object:
type: object
properties:
array_of_text: text
script: "emit(params._source[\"json_field\"])"
source_indexed_field: "json_field"

- do:
index:
index: test
id: 1
body: {
text: "Email: example@example.com, Visit https://example.com for more info.",
json_field: "{\"array_of_text\": [\"Email: example@example.com, Visit https://example.com for more info.\", \"Email: example@example.com, Visit https://example.com for more info.\"]}}"
}

- do:
indices.refresh:
index: [test]
- do:
search:
index: test
q: "derived_object.array_of_text:example.com"
analyzer: standard

- match: { hits.total.value: 1 }

- do:
search:
index: test
q: "derived_object.array_of_text:example.com"
analyzer: simple

- match: { hits.total.value: 1 }

0 comments on commit 4ffd4d5

Please sign in to comment.