Skip to content

Commit

Permalink
Fix query string and add integ tests
Browse files Browse the repository at this point in the history
Signed-off-by: Rishabh Maurya <[email protected]>
  • Loading branch information
rishabhmaurya committed May 16, 2024
1 parent b394d02 commit 2c7c6dc
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,20 @@
gte: 3

- match: { hits.total: 4 }

# Tests for query string
- do:
search:
rest_total_hits_as_int: true
index: test
q: "derived_keyword:foo"

- match: { hits.total: 1 }

- do:
search:
rest_total_hits_as_int: true
index: test
q: derived_object.keyword:json_keyword1

- match: { hits.total: 1 }
Original file line number Diff line number Diff line change
Expand Up @@ -457,3 +457,33 @@
gte: 3

- match: { hits.total: 4 }

# Tests for query string
- do:
search:
body:
derived:
derived_keyword:
type: keyword
script: "emit(params._source[\"keyword\"])"
rest_total_hits_as_int: true
index: test
q: "derived_keyword:foo"

- match: { hits.total: 1 }

- do:
search:
body:
derived:
derived_object:
type: object
properties:
keyword: keyword
script: "emit(params._source[\"json_field\"])"
source_indexed_field: "json_field"
rest_total_hits_as_int: true
index: test
q: derived_object.keyword:json_keyword1

- match: { hits.total: 1 }
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,111 @@ setup:
- match: { hits.hits.1.fields.derived_object\.boolean.0: false }
- match: { hits.hits.1.fields.derived_object\.array_of_long.0: 2 }
- match: { hits.hits.1.fields.derived_object\.array_of_long.1: 3 }


---
"Test highlight":
- do:
indices.create:
index: test
body:
mappings:
properties:
text:
type: text
array_of_text:
type: text
json_field:
type: text
derived:
derived_text:
type: text
script: "emit(params._source[\"text\"])"
derived_keyword:
type: keyword
script: "emit(params._source[\"keyword\"])"
derived_array_of_text:
type: text
script: "emit(params._source[\"array_of_text\"][0]);emit(params._source[\"array_of_text\"][1]);"
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: "peter piper",
keyword: "foo",
long: 1,
float: 1.0,
double: 1.0,
date: "2017-01-01T00:00:00Z",
geo: [0.0, 20.0],
ip: "192.168.0.1",
boolean: true,
array_of_text: ["The quick brown fox is brown", "The quick brown fox is black"],
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_text\": [\"The quick brown fox is brown\", \"The quick brown fox is black\"]}}"
}

- do:
index:
index: test
id: 2
body: {
text: "piper picked a peck",
keyword: "bar",
long: 2,
float: 2.0,
double: 2.0,
date: "2017-01-02T00:00:00Z",
geo: [10.0, 30.0],
ip: "192.168.0.2",
boolean: false,
array_of_text: ["The quick brown fox is brown", "The quick brown fox is black"],
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_text\": [\"The quick brown fox is brown\", \"The quick brown fox is black\"]}}"
}

- do:
indices.refresh:
index: [test]
- do:
search:
rest_total_hits_as_int: true
body: { "query" : {"multi_match" : { "query" : "piper", "fields" : [ "derived_text"] } },
"fields": [derived_text],
"highlight" : { "type" : "unified", "fields" : { "derived_text" : {} } }
}

- match: {hits.hits.0.highlight.derived_text.0: "peter <em>piper</em>"}


- do:
search:
rest_total_hits_as_int: true
body: { "query" : {"multi_match" : { "query" : "quick brown", "fields" : [ "derived_array_of_text"] } },
"fields": [derived_array_of_text],
"highlight" : { "type" : "unified", "fields" : { "derived_array_of_text" : {} } }
}

- match: {hits.hits.0.highlight.derived_array_of_text.0: "The <em>quick</em> <em>brown</em> fox is <em>brown</em>"}

- do:
search:
rest_total_hits_as_int: true
index: test
body:
query:
match_phrase:
derived_object.array_of_text:
query: "quick brown"
highlight:
type: unified
fields:
derived_object.array_of_text: {}

- match: {hits.hits.0.highlight.derived_object\.array_of_text.0: "The <em>quick</em> <em>brown</em> fox is <em>brown</em>"}
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ static Map<String, Float> resolveMappingField(
}

MappedFieldType fieldType = context.getMapperService().fieldType(fieldName);
if (fieldType == null) {
fieldType = context.resolveDerivedFieldType(fieldName);
}
if (fieldType == null) {
continue;
}
Expand Down

0 comments on commit 2c7c6dc

Please sign in to comment.