Skip to content

Commit

Permalink
add more integ test for update mapping and fetch derived fields
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 15, 2024
1 parent 1dd9df6 commit 07fed11
Show file tree
Hide file tree
Showing 4 changed files with 796 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"derived_field using index mapping definition":
"Test derived_field supported type using index mapping definition":
- skip:
version: " - 2.14.99"
reason: "derived_field feature was added in 2.15"
Expand Down Expand Up @@ -27,6 +27,8 @@
type: ip
boolean:
type: boolean
array_of_long:
type: long
json_field:
type: text
derived:
Expand Down Expand Up @@ -61,6 +63,9 @@
derived_boolean:
type: boolean
script: "emit(params._source[\"boolean\"])"
derived_array_of_long:
type: long
script: "emit(params._source[\"array_of_long\"][0]);emit(params._source[\"array_of_long\"][1]);"
derived_object:
type: object
properties:
Expand All @@ -82,7 +87,8 @@
geo: [0.0, 20.0],
ip: "192.168.0.1",
boolean: true,
json_field: "{\"keyword\":\"json_keyword1\",\"long\":10,\"float\":10.0,\"double\":10.0,\"date\":\"2021-01-01T00:00:00Z\",\"ip\":\"10.0.0.1\",\"boolean\":true}"
array_of_long: [1, 2],
json_field: "{\"keyword\":\"json_keyword1\",\"long\":10,\"float\":10.0,\"double\":10.0,\"date\":\"2021-01-01T00:00:00Z\",\"ip\":\"10.0.0.1\",\"boolean\":true, \"array_of_long\": [1, 2]}}"
}

- do:
Expand All @@ -99,7 +105,8 @@
geo: [10.0, 30.0],
ip: "192.168.0.2",
boolean: false,
json_field: "{\"keyword\":\"json_keyword2\",\"long\":20,\"float\":20.0,\"double\":20.0,\"date\":\"2021-02-01T00:00:00Z\",\"ip\":\"10.0.0.2\",\"boolean\":false}"
array_of_long: [2, 3],
json_field: "{\"keyword\":\"json_keyword2\",\"long\":20,\"float\":20.0,\"double\":20.0,\"date\":\"2021-02-01T00:00:00Z\",\"ip\":\"10.0.0.2\",\"boolean\":false, \"array_of_long\": [2, 3]}}"
}

- do:
Expand All @@ -116,7 +123,8 @@
geo: [20.0, 40.0],
ip: "192.168.0.3",
boolean: true,
json_field: "{\"keyword\":\"json_keyword3\",\"long\":30,\"float\":30.0,\"double\":30.0,\"date\":\"2021-03-01T00:00:00Z\",\"ip\":\"10.0.0.3\",\"boolean\":true}"
array_of_long: [3, 4],
json_field: "{\"keyword\":\"json_keyword3\",\"long\":30,\"float\":30.0,\"double\":30.0,\"date\":\"2021-03-01T00:00:00Z\",\"ip\":\"10.0.0.3\",\"boolean\":true, \"array_of_long\": [3, 4]}"
}

- do:
Expand All @@ -133,7 +141,8 @@
geo: [30.0, 50.0],
ip: "192.168.0.4",
boolean: false,
json_field: "{\"keyword\":\"json_keyword4\",\"long\":40,\"float\":40.0,\"double\":40.0,\"date\":\"2021-04-01T00:00:00Z\",\"ip\":\"10.0.0.4\",\"boolean\":false}"
array_of_long: [4, 5],
json_field: "{\"keyword\":\"json_keyword4\",\"long\":40,\"float\":40.0,\"double\":40.0,\"date\":\"2021-04-01T00:00:00Z\",\"ip\":\"10.0.0.4\",\"boolean\":false, \"array_of_long\": [4, 5]}"
}

- do:
Expand All @@ -150,7 +159,8 @@
geo: [40.0, 60.0],
ip: "192.168.0.5",
boolean: true,
json_field: "{\"keyword\":\"json_keyword5\",\"long\":50,\"float\":50.0,\"double\":50.0,\"date\":\"2021-05-01T00:00:00Z\",\"ip\":\"10.0.0.5\",\"boolean\":true}"
array_of_long: [5, 6],
json_field: "{\"keyword\":\"json_keyword5\",\"long\":50,\"float\":50.0,\"double\":50.0,\"date\":\"2021-05-01T00:00:00Z\",\"ip\":\"10.0.0.5\",\"boolean\":true, \"array_of_long\": [5, 6]}"
}

- do:
Expand Down Expand Up @@ -276,6 +286,19 @@

- match: { hits.total: 3 }

# Tests for derived_array_of_long
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:
range:
derived_array_of_long:
gte: 3

- match: { hits.total: 4 }

# Tests for derived_object.keyword
- do:
search:
Expand Down Expand Up @@ -366,3 +389,16 @@
value: true

- match: { hits.total: 3 }

# Tests for derived_object.array_of_long
- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:
range:
derived_object.array_of_long:
gte: 3

- match: { hits.total: 4 }
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
---
"Test create and update mapping for derived fields":
- skip:
version: " - 2.14.99"
reason: "derived_field feature was added in 2.15"
- do:
indices.create:
index: test_index

- do:
indices.put_mapping:
index: test_index
body:
properties:
text:
type: text
json_field:
type: text
derived:
derived_text:
type: text
script: "emit(params._source[\"text\"])"
derived_text_source_indexed_field:
type: keyword
script: "emit(params._source[\"text\"])"
source_indexed_field: "text"
derived_date:
type: date
script: "emit(params._source[\"keyword\"])"
derived_object:
type: object
properties:
keyword: keyword
script: "emit(params._source[\"json_field\"])"
source_indexed_field: "json_field"

- do:
indices.get_mapping:
index: test_index

- match: {test_index.mappings.derived.derived_text.type: text}
- match: {test_index.mappings.derived.derived_text_source_indexed_field.type: keyword}
- match: {test_index.mappings.derived.derived_text_source_indexed_field.source_indexed_field: text}
- match: {test_index.mappings.derived.derived_date.type: date}
- match: {test_index.mappings.derived.derived_object.type: object}
- match: {test_index.mappings.derived.derived_object.properties.keyword: keyword}
- match: {test_index.mappings.derived.derived_object.source_indexed_field: json_field}


- do:
indices.put_mapping:
index: test_index
body:
properties:
text:
type: text
json_field:
type: text
derived:
derived_text:
type: keyword
script: "emit(params._source[\"text\"])"
derived_text_source_indexed_field:
type: text
script: "emit(params._source[\"text\"])"
source_indexed_field: "text"
derived_date:
type: keyword
script: "emit(params._source[\"keyword\"])"
derived_object:
type: object
properties:
keyword: text
script: "emit(params._source[\"text\"])"
source_indexed_field: "text"
format: "dd-MM-yyyy"
ignore_malformed: true

- do:
indices.get_mapping:
index: test_index

- match: {test_index.mappings.derived.derived_text.type: keyword}
- match: {test_index.mappings.derived.derived_text_source_indexed_field.type: text}
- match: {test_index.mappings.derived.derived_text_source_indexed_field.source_indexed_field: text}
- match: {test_index.mappings.derived.derived_date.type: keyword}
- match: {test_index.mappings.derived.derived_object.type: object}
- match: {test_index.mappings.derived.derived_object.properties.keyword: text}
- match: {test_index.mappings.derived.derived_object.source_indexed_field: text}
- match: {test_index.mappings.derived.derived_object.format: "dd-MM-yyyy"}
- match: {test_index.mappings.derived.derived_object.ignore_malformed: true}


- do:
indices.put_mapping:
index: test_index
body:
properties:
text:
type: text
json_field:
type: text
derived:
derived_object:
type: object
properties:
keyword: keyword
script: "emit(params._source[\"json_field\"])"
source_indexed_field: "json_field"
ignore_malformed: false

- do:
indices.get_mapping:
index: test_index

- match: {test_index.mappings.derived.derived_text.type: keyword}
- match: {test_index.mappings.derived.derived_text_source_indexed_field.type: text}
- match: {test_index.mappings.derived.derived_text_source_indexed_field.source_indexed_field: text}
- match: {test_index.mappings.derived.derived_date.type: keyword}
- match: {test_index.mappings.derived.derived_object.type: object}
- match: {test_index.mappings.derived.derived_object.properties.keyword: keyword}
- match: {test_index.mappings.derived.derived_object.source_indexed_field: json_field}
- is_false: test_index.mappings.derived.derived_object.ignore_malformed
Loading

0 comments on commit 07fed11

Please sign in to comment.