mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-06-28 09:28:55 -04:00
Runtime fields to optionally ignore script errors (#92380)
Currently Elasticsearch always returns a shard failure once a runtime error arises from using a runtime field, the exception being script-less runtime fields. This also means that execution of the query for that shard stops, which is okay for development and exploration. In a production scenario, however, it is often desirable to ignore runtime errors and continue with the query execution. This change adds a new a new on_script_error parameter to runtime field definitions similar to the already existing parameter for index-time scripted fields. When `on_script_error` is set to `continue`, errors from script execution are effectively ignored. This means affected documents don't show up in query results, but also don't prevent other matches from the same shard. Runtime fields accessed through the fields API don't return values on errors, aggregations will ignore documents that throw errors. Note that this change affects scripted runtime fields only, while leaving default behaviour untouched. Also, ignored errors are not reported back to users for now. Relates to #72143
This commit is contained in:
parent
3bbf202843
commit
8067f01d48
78 changed files with 2184 additions and 303 deletions
|
@ -0,0 +1,124 @@
|
|||
---
|
||||
setup:
|
||||
- do:
|
||||
indices.create:
|
||||
index: test
|
||||
body:
|
||||
settings:
|
||||
number_of_shards: 1
|
||||
number_of_replicas: 0
|
||||
mappings:
|
||||
runtime:
|
||||
rtf:
|
||||
type: composite
|
||||
on_script_error: continue
|
||||
script:
|
||||
source: |
|
||||
if (doc["message"].value.equals("fail")) throw new Exception("error");
|
||||
emit('msg', doc['message'].value);
|
||||
fields:
|
||||
msg:
|
||||
type: keyword
|
||||
rtf_strict:
|
||||
type: composite
|
||||
on_script_error: fail
|
||||
script:
|
||||
source: |
|
||||
if (doc["message"].value.equals("fail")) throw new Exception("error");
|
||||
emit('msg', doc['message'].value);
|
||||
fields:
|
||||
msg:
|
||||
type: keyword
|
||||
properties:
|
||||
timestamp:
|
||||
type: date
|
||||
message:
|
||||
type: keyword
|
||||
|
||||
- do:
|
||||
bulk:
|
||||
index: test
|
||||
refresh: true
|
||||
body: |
|
||||
{"index":{}}
|
||||
{"timestamp": "1998-04-30T14:30:17-05:00", "message" : "this is okay"}
|
||||
{"index":{}}
|
||||
{"timestamp": "1998-04-30T14:30:53-05:00", "message" : "fail"}
|
||||
|
||||
---
|
||||
"query with continue on error":
|
||||
- do:
|
||||
search:
|
||||
index: test
|
||||
body:
|
||||
query:
|
||||
term:
|
||||
rtf.msg: "this is okay"
|
||||
- match: { hits.total.value: 1 }
|
||||
- match: { hits.hits.0._source.message: "this is okay"}
|
||||
|
||||
---
|
||||
"query with fail on error":
|
||||
- do:
|
||||
catch: /type=script_exception, reason=runtime error/
|
||||
search:
|
||||
index: test
|
||||
body:
|
||||
query:
|
||||
term:
|
||||
rtf_strict.msg: "this is okay"
|
||||
|
||||
---
|
||||
"query with search time field":
|
||||
- do:
|
||||
search:
|
||||
index: test
|
||||
body:
|
||||
query:
|
||||
term:
|
||||
rtf_search.msg: "this is okay"
|
||||
runtime_mappings:
|
||||
rtf_search:
|
||||
type: composite
|
||||
on_script_error: continue
|
||||
script:
|
||||
source: |
|
||||
if (doc["message"].value.equals("fail")) throw new Exception("error");
|
||||
emit('msg', doc['message'].value);
|
||||
fields:
|
||||
msg:
|
||||
type: keyword
|
||||
|
||||
- match: { hits.total.value: 1 }
|
||||
- match: { hits.hits.0._source.message: "this is okay"}
|
||||
|
||||
---
|
||||
fetch:
|
||||
- do:
|
||||
search:
|
||||
index: test
|
||||
body:
|
||||
sort: timestamp
|
||||
fields:
|
||||
- message
|
||||
- rtf.msg
|
||||
- match: {hits.total.value: 2}
|
||||
- match: {hits.hits.0.fields.message: ["this is okay"] }
|
||||
- match: {hits.hits.0.fields.rtf\.msg: ["this is okay"] }
|
||||
- match: {hits.hits.1.fields.message: ["fail"] }
|
||||
- is_false: hits.hits.1.fields.rtf.msg
|
||||
|
||||
---
|
||||
"terms agg":
|
||||
- do:
|
||||
search:
|
||||
index: test
|
||||
body:
|
||||
aggs:
|
||||
messages:
|
||||
terms:
|
||||
field: rtf.msg
|
||||
- match: { hits.total.value: 2}
|
||||
- length: { aggregations.messages.buckets: 1 }
|
||||
- match: { aggregations.messages.buckets.0.key: "this is okay" }
|
||||
- match: { aggregations.messages.buckets.0.doc_count: 1 }
|
|
@ -0,0 +1,216 @@
|
|||
---
|
||||
setup:
|
||||
- do:
|
||||
indices.create:
|
||||
index: testindex
|
||||
body:
|
||||
settings:
|
||||
number_of_shards: 1
|
||||
mappings:
|
||||
runtime:
|
||||
first_char:
|
||||
type: keyword
|
||||
script: |
|
||||
emit(doc['name'].value.substring(0,1));
|
||||
on_script_error: continue
|
||||
first_char_strict_error:
|
||||
type: keyword
|
||||
script: |
|
||||
emit(doc['name'].value.substring(0,1));
|
||||
on_script_error: fail
|
||||
properties:
|
||||
name:
|
||||
type: keyword
|
||||
|
||||
- do:
|
||||
bulk:
|
||||
index: testindex
|
||||
refresh: true
|
||||
body: |
|
||||
{"index":{}}
|
||||
{"name": "foo"}
|
||||
{"index":{}}
|
||||
{"name": ""}
|
||||
|
||||
---
|
||||
"Query rtf with on_script_error continue":
|
||||
- do:
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query:
|
||||
match:
|
||||
first_char: "f"
|
||||
fields: [ name, first_char ]
|
||||
- match: { hits.total.value: 1 }
|
||||
- match: { hits.hits.0.fields.name: [ foo ] }
|
||||
- match: { hits.hits.0.fields.first_char: [ f ] }
|
||||
|
||||
---
|
||||
"Query rtf with on_script_error fail":
|
||||
- do:
|
||||
catch: /type=script_exception, reason=runtime error/
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query:
|
||||
match:
|
||||
first_char_strict_error: "f"
|
||||
fields: [ name, first_char_strict_error ]
|
||||
|
||||
---
|
||||
"Aggregate on rtf with on_script_error continue":
|
||||
- do:
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
aggs:
|
||||
firstchar:
|
||||
terms:
|
||||
field: first_char
|
||||
- length: { aggregations.firstchar.buckets: 1 }
|
||||
- match: { aggregations.firstchar.buckets.0.key: "f" }
|
||||
|
||||
---
|
||||
"Aggregate on rtf with on_script_error fail":
|
||||
- do:
|
||||
catch: /type=script_exception, reason=runtime error/
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
aggs:
|
||||
firstchar:
|
||||
terms:
|
||||
field: first_char_strict_error
|
||||
|
||||
---
|
||||
"Fields retrieval with ignoring error":
|
||||
- do:
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query: { match_all: { } }
|
||||
fields: [ name, first_char ]
|
||||
- match: { hits.total.value: 2 }
|
||||
- match: { hits.hits.0.fields.name: [ foo ] }
|
||||
- match: { hits.hits.0.fields.first_char: [ f ] }
|
||||
- match: { hits.hits.1.fields.name: [ "" ] }
|
||||
- is_false: hits.hits.1.fields.first_char
|
||||
|
||||
---
|
||||
"Fields retrieval with failing on error":
|
||||
- do:
|
||||
catch: /type=script_exception, reason=runtime error/
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query: { match_all: { } }
|
||||
fields: [ name, first_char_strict_error ]
|
||||
|
||||
---
|
||||
"Sorting with ignoring error":
|
||||
- do:
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query: { match_all: { } }
|
||||
fields: [ name ]
|
||||
sort: first_char
|
||||
- match: { hits.total.value: 2 }
|
||||
- match: { hits.hits.0.fields.name: [ foo ] }
|
||||
- match: { hits.hits.1.fields.name: [ "" ] }
|
||||
|
||||
---
|
||||
"Sorting with with failing on error":
|
||||
- do:
|
||||
catch: /type=script_exception, reason=runtime error/
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query: { match_all: { } }
|
||||
fields: [ name ]
|
||||
sort: first_char_strict_error
|
||||
|
||||
---
|
||||
"Query search time rtf with on_script_error continue":
|
||||
- do:
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query:
|
||||
match:
|
||||
first_char_search: "f"
|
||||
fields: [ name, first_char_search ]
|
||||
runtime_mappings:
|
||||
first_char_search:
|
||||
type: keyword
|
||||
script: |
|
||||
emit(doc['name'].value.substring(0,1));
|
||||
on_script_error: continue
|
||||
|
||||
- match: { hits.total.value: 1 }
|
||||
- match: { hits.hits.0.fields.name: [ foo ] }
|
||||
- match: { hits.hits.0.fields.first_char_search: [ f ] }
|
||||
|
||||
---
|
||||
"Query search time rtf with on_script_error fail":
|
||||
- do:
|
||||
catch: /type=script_exception, reason=runtime error/
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query:
|
||||
match:
|
||||
first_char_search: "f"
|
||||
fields: [ name, first_char_search ]
|
||||
runtime_mappings:
|
||||
first_char_search:
|
||||
type: keyword
|
||||
script: |
|
||||
emit(doc['name'].value.substring(0,1));
|
||||
on_script_error: fail
|
||||
|
||||
---
|
||||
"Change error behaviour for lenient runtime field":
|
||||
|
||||
- do:
|
||||
indices.put_mapping:
|
||||
index: testindex
|
||||
body:
|
||||
runtime:
|
||||
first_char_variant:
|
||||
type: keyword
|
||||
script: |
|
||||
emit(doc['name'].value.substring(0,1));
|
||||
|
||||
- do:
|
||||
catch: /type=script_exception, reason=runtime error/
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query:
|
||||
match:
|
||||
first_char_variant: "f"
|
||||
|
||||
- do:
|
||||
indices.put_mapping:
|
||||
index: testindex
|
||||
body:
|
||||
runtime:
|
||||
first_char_variant:
|
||||
type: keyword
|
||||
script: |
|
||||
emit(doc['name'].value.substring(0,1));
|
||||
on_script_error: continue
|
||||
|
||||
- do:
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query:
|
||||
match:
|
||||
first_char_variant: "f"
|
||||
fields: [ name, first_char_variant ]
|
||||
- match: { hits.total.value: 1 }
|
||||
- match: { hits.hits.0.fields.name: [ foo ] }
|
||||
- match: { hits.hits.0.fields.first_char_variant: [ f ] }
|
|
@ -0,0 +1,176 @@
|
|||
---
|
||||
setup:
|
||||
- do:
|
||||
indices.create:
|
||||
index: testindex
|
||||
body:
|
||||
settings:
|
||||
number_of_shards: 1
|
||||
number_of_replicas: 0
|
||||
mappings:
|
||||
runtime:
|
||||
rtf:
|
||||
type: long
|
||||
script: |
|
||||
if(doc['name'].value.equals("")) throw new Exception("empty");
|
||||
emit(doc['name'].value.length());
|
||||
on_script_error: continue
|
||||
rtf_strict_error:
|
||||
type: long
|
||||
script: |
|
||||
if(doc['name'].value.equals("")) throw new Exception("empty");
|
||||
emit(doc['name'].value.length());
|
||||
on_script_error: fail
|
||||
properties:
|
||||
name:
|
||||
type: keyword
|
||||
|
||||
- do:
|
||||
bulk:
|
||||
index: testindex
|
||||
refresh: true
|
||||
body: |
|
||||
{"index":{}}
|
||||
{"name": "foo"}
|
||||
{"index":{}}
|
||||
{"name": ""}
|
||||
|
||||
---
|
||||
"Query rtf with on_script_error continue":
|
||||
- do:
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query:
|
||||
match:
|
||||
rtf: 3
|
||||
fields: [ name, rtf ]
|
||||
- match: { hits.total.value: 1 }
|
||||
- match: { hits.hits.0.fields.name: [ foo ] }
|
||||
- match: { hits.hits.0.fields.rtf: [ 3 ] }
|
||||
|
||||
---
|
||||
"Query rtf with on_script_error fail":
|
||||
- do:
|
||||
catch: /type=script_exception, reason=runtime error/
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query:
|
||||
match:
|
||||
rtf_strict_error: 3
|
||||
fields: [ name, rtf_strict_error ]
|
||||
|
||||
---
|
||||
"Aggregate on rtf with on_script_error continue":
|
||||
- do:
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
aggs:
|
||||
firstchar:
|
||||
terms:
|
||||
field: rtf
|
||||
- length: { aggregations.firstchar.buckets: 1 }
|
||||
- match: { aggregations.firstchar.buckets.0.key: 3 }
|
||||
|
||||
---
|
||||
"Aggregate on rtf with on_script_error fail":
|
||||
- do:
|
||||
catch: /type=script_exception, reason=runtime error/
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
aggs:
|
||||
firstchar:
|
||||
terms:
|
||||
field: rtf_strict_error
|
||||
|
||||
---
|
||||
"Fields retrieval with ignoring error":
|
||||
- do:
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query: { match_all: { } }
|
||||
fields: [ name, rtf ]
|
||||
- match: { hits.total.value: 2 }
|
||||
- match: { hits.hits.0.fields.name: [ foo ] }
|
||||
- match: { hits.hits.0.fields.rtf: [ 3 ] }
|
||||
- match: { hits.hits.1.fields.name: [ "" ] }
|
||||
- is_false: hits.hits.1.fields.rtf
|
||||
|
||||
---
|
||||
"Fields retrieval with failing on error":
|
||||
- do:
|
||||
catch: /type=script_exception, reason=runtime error/
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query: { match_all: { } }
|
||||
fields: [ name, rtf_strict_error ]
|
||||
|
||||
---
|
||||
"Sorting with ignoring error":
|
||||
- do:
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query: { match_all: { } }
|
||||
fields: [ name ]
|
||||
sort: rtf
|
||||
- match: { hits.total.value: 2 }
|
||||
- match: { hits.hits.0.fields.name: [ foo ] }
|
||||
- match: { hits.hits.1.fields.name: [ "" ] }
|
||||
|
||||
---
|
||||
"Sorting with with failing on error":
|
||||
- do:
|
||||
catch: /type=script_exception, reason=runtime error/
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query: { match_all: { } }
|
||||
fields: [ name ]
|
||||
sort: rtf_strict_error
|
||||
|
||||
---
|
||||
"Query search time rtf with on_script_error continue":
|
||||
- do:
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query:
|
||||
match:
|
||||
rtf_search: 3
|
||||
fields: [ name, rtf_search ]
|
||||
runtime_mappings:
|
||||
rtf_search:
|
||||
type: long
|
||||
script: |
|
||||
if(doc['name'].value.equals("")) throw new Exception("empty");
|
||||
emit(doc['name'].value.length());
|
||||
on_script_error: continue
|
||||
|
||||
- match: { hits.total.value: 1 }
|
||||
- match: { hits.hits.0.fields.name: [ foo ] }
|
||||
- match: { hits.hits.0.fields.rtf_search: [ 3 ] }
|
||||
|
||||
---
|
||||
"Query search time rtf with on_script_error fail":
|
||||
- do:
|
||||
catch: /type=script_exception, reason=runtime error/
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query:
|
||||
match:
|
||||
rtf_search: 3
|
||||
fields: [ name, rtf_search ]
|
||||
runtime_mappings:
|
||||
rtf_search:
|
||||
type: long
|
||||
script: |
|
||||
if(doc['name'].value.equals("")) throw new Exception("empty");
|
||||
emit(doc['name'].value.length());
|
||||
on_script_error: fail
|
|
@ -0,0 +1,176 @@
|
|||
---
|
||||
setup:
|
||||
- do:
|
||||
indices.create:
|
||||
index: testindex
|
||||
body:
|
||||
settings:
|
||||
number_of_shards: 1
|
||||
number_of_replicas: 0
|
||||
mappings:
|
||||
runtime:
|
||||
rtf:
|
||||
type: double
|
||||
script: |
|
||||
if(doc['name'].value.equals("")) throw new Exception("empty");
|
||||
emit(doc['name'].value.length());
|
||||
on_script_error: continue
|
||||
rtf_strict_error:
|
||||
type: double
|
||||
script: |
|
||||
if(doc['name'].value.equals("")) throw new Exception("empty");
|
||||
emit(doc['name'].value.length());
|
||||
on_script_error: fail
|
||||
properties:
|
||||
name:
|
||||
type: keyword
|
||||
|
||||
- do:
|
||||
bulk:
|
||||
index: testindex
|
||||
refresh: true
|
||||
body: |
|
||||
{"index":{}}
|
||||
{"name": "foo"}
|
||||
{"index":{}}
|
||||
{"name": ""}
|
||||
|
||||
---
|
||||
"Query rtf with on_script_error continue":
|
||||
- do:
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query:
|
||||
match:
|
||||
rtf: 3
|
||||
fields: [ name, rtf ]
|
||||
- match: { hits.total.value: 1 }
|
||||
- match: { hits.hits.0.fields.name: [ foo ] }
|
||||
- match: { hits.hits.0.fields.rtf: [ 3.0 ] }
|
||||
|
||||
---
|
||||
"Query rtf with on_script_error fail":
|
||||
- do:
|
||||
catch: /type=script_exception, reason=runtime error/
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query:
|
||||
match:
|
||||
rtf_strict_error: 3
|
||||
fields: [ name, rtf_strict_error ]
|
||||
|
||||
---
|
||||
"Aggregate on rtf with on_script_error continue":
|
||||
- do:
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
aggs:
|
||||
firstchar:
|
||||
terms:
|
||||
field: rtf
|
||||
- length: { aggregations.firstchar.buckets: 1 }
|
||||
- match: { aggregations.firstchar.buckets.0.key: 3.0 }
|
||||
|
||||
---
|
||||
"Aggregate on rtf with on_script_error fail":
|
||||
- do:
|
||||
catch: /type=script_exception, reason=runtime error/
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
aggs:
|
||||
firstchar:
|
||||
terms:
|
||||
field: rtf_strict_error
|
||||
|
||||
---
|
||||
"Fields retrieval with ignoring error":
|
||||
- do:
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query: { match_all: { } }
|
||||
fields: [ name, rtf ]
|
||||
- match: { hits.total.value: 2 }
|
||||
- match: { hits.hits.0.fields.name: [ foo ] }
|
||||
- match: { hits.hits.0.fields.rtf: [ 3.0 ] }
|
||||
- match: { hits.hits.1.fields.name: [ "" ] }
|
||||
- is_false: hits.hits.1.fields.rtf
|
||||
|
||||
---
|
||||
"Fields retrieval with failing on error":
|
||||
- do:
|
||||
catch: /type=script_exception, reason=runtime error/
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query: { match_all: { } }
|
||||
fields: [ name, rtf_strict_error ]
|
||||
|
||||
---
|
||||
"Sorting with ignoring error":
|
||||
- do:
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query: { match_all: { } }
|
||||
fields: [ name ]
|
||||
sort: rtf
|
||||
- match: { hits.total.value: 2 }
|
||||
- match: { hits.hits.0.fields.name: [ foo ] }
|
||||
- match: { hits.hits.1.fields.name: [ "" ] }
|
||||
|
||||
---
|
||||
"Sorting with with failing on error":
|
||||
- do:
|
||||
catch: /type=script_exception, reason=runtime error/
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query: { match_all: { } }
|
||||
fields: [ name ]
|
||||
sort: rtf_strict_error
|
||||
|
||||
---
|
||||
"Query search time rtf with on_script_error continue":
|
||||
- do:
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query:
|
||||
match:
|
||||
rtf_search: 3
|
||||
fields: [ name, rtf_search ]
|
||||
runtime_mappings:
|
||||
rtf_search:
|
||||
type: double
|
||||
script: |
|
||||
if(doc['name'].value.equals("")) throw new Exception("empty");
|
||||
emit(doc['name'].value.length());
|
||||
on_script_error: continue
|
||||
|
||||
- match: { hits.total.value: 1 }
|
||||
- match: { hits.hits.0.fields.name: [ foo ] }
|
||||
- match: { hits.hits.0.fields.rtf_search: [ 3.0 ] }
|
||||
|
||||
---
|
||||
"Query search time rtf with on_script_error fail":
|
||||
- do:
|
||||
catch: /type=script_exception, reason=runtime error/
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query:
|
||||
match:
|
||||
rtf_search: 3
|
||||
fields: [ name, rtf_search ]
|
||||
runtime_mappings:
|
||||
rtf_search:
|
||||
type: double
|
||||
script: |
|
||||
if(doc['name'].value.equals("")) throw new Exception("empty");
|
||||
emit(doc['name'].value.length());
|
||||
on_script_error: fail
|
|
@ -0,0 +1,184 @@
|
|||
---
|
||||
setup:
|
||||
- do:
|
||||
indices.create:
|
||||
index: testindex
|
||||
body:
|
||||
settings:
|
||||
number_of_shards: 1
|
||||
number_of_replicas: 0
|
||||
mappings:
|
||||
runtime:
|
||||
rtf:
|
||||
type: date
|
||||
format: yyyy-MM-dd
|
||||
script: |
|
||||
if(doc['millis_since_epoch'].value < 0) throw new Exception("date before 1970");
|
||||
emit(doc['millis_since_epoch'].value);
|
||||
on_script_error: continue
|
||||
rtf_strict_error:
|
||||
type: date
|
||||
format: yyyy-MM-dd
|
||||
script: |
|
||||
if(doc['millis_since_epoch'].value < 0) throw new Exception("date before 1970");
|
||||
emit(doc['millis_since_epoch'].value);
|
||||
on_script_error: fail
|
||||
properties:
|
||||
millis_since_epoch:
|
||||
type: long
|
||||
|
||||
- do:
|
||||
bulk:
|
||||
index: testindex
|
||||
refresh: true
|
||||
body: |
|
||||
{"index":{}}
|
||||
{"millis_since_epoch": 1671033474411}
|
||||
{"index":{}}
|
||||
{"millis_since_epoch": -1}
|
||||
|
||||
---
|
||||
"Query rtf with on_script_error continue":
|
||||
- do:
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query:
|
||||
range:
|
||||
rtf:
|
||||
gte: "2022-12-14"
|
||||
fields: [ millis_since_epoch, rtf ]
|
||||
- match: { hits.total.value: 1 }
|
||||
- match: { hits.hits.0.fields.millis_since_epoch: [ 1671033474411 ] }
|
||||
- match: { hits.hits.0.fields.rtf: [ "2022-12-14" ] }
|
||||
|
||||
---
|
||||
"Query rtf with on_script_error fail":
|
||||
- do:
|
||||
catch: /type=script_exception, reason=runtime error/
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query:
|
||||
range:
|
||||
rtf_strict_error:
|
||||
gte: "2022-12-14"
|
||||
fields: [ millis_since_epoch, rtf_strict_error ]
|
||||
|
||||
---
|
||||
"Aggregate on rtf with on_script_error continue":
|
||||
- do:
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
aggs:
|
||||
firstchar:
|
||||
terms:
|
||||
field: rtf
|
||||
- length: { aggregations.firstchar.buckets: 1 }
|
||||
- match: { aggregations.firstchar.buckets.0.key_as_string: "2022-12-14" }
|
||||
|
||||
---
|
||||
"Aggregate on rtf with on_script_error fail":
|
||||
- do:
|
||||
catch: /type=script_exception, reason=runtime error/
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
aggs:
|
||||
firstchar:
|
||||
terms:
|
||||
field: rtf_strict_error
|
||||
|
||||
---
|
||||
"Fields retrieval with ignoring error":
|
||||
- do:
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query: { match_all: { } }
|
||||
fields: [ millis_since_epoch, rtf ]
|
||||
- match: { hits.total.value: 2 }
|
||||
- match: { hits.hits.0.fields.millis_since_epoch: [ 1671033474411 ] }
|
||||
- match: { hits.hits.0.fields.rtf: [ "2022-12-14" ] }
|
||||
- match: { hits.hits.1.fields.millis_since_epoch: [ -1 ] }
|
||||
- is_false: hits.hits.1.fields.rtf
|
||||
|
||||
---
|
||||
"Fields retrieval with failing on error":
|
||||
- do:
|
||||
catch: /type=script_exception, reason=runtime error/
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query: { match_all: { } }
|
||||
fields: [ millis_since_epoch, rtf_strict_error ]
|
||||
|
||||
---
|
||||
"Sorting with ignoring error":
|
||||
- do:
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query: { match_all: { } }
|
||||
fields: [ millis_since_epoch ]
|
||||
sort: rtf
|
||||
- match: { hits.total.value: 2 }
|
||||
- match: { hits.hits.0.fields.millis_since_epoch: [ 1671033474411 ] }
|
||||
- match: { hits.hits.1.fields.millis_since_epoch: [ -1 ] }
|
||||
|
||||
---
|
||||
"Sorting with with failing on error":
|
||||
- do:
|
||||
catch: /type=script_exception, reason=runtime error/
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query: { match_all: { } }
|
||||
fields: [ millis_since_epoch ]
|
||||
sort: rtf_strict_error
|
||||
|
||||
---
|
||||
"Query search time rtf with on_script_error continue":
|
||||
- do:
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query:
|
||||
range:
|
||||
rtf_search:
|
||||
gte: "2022-12-14"
|
||||
fields: [ millis_since_epoch, rtf_search ]
|
||||
runtime_mappings:
|
||||
rtf_search:
|
||||
type: date
|
||||
format: yyyy-MM-dd
|
||||
script: |
|
||||
if(doc['millis_since_epoch'].value < 0) throw new Exception("date before 1970");
|
||||
emit(doc['millis_since_epoch'].value);
|
||||
on_script_error: continue
|
||||
|
||||
- match: { hits.total.value: 1 }
|
||||
- match: { hits.hits.0.fields.millis_since_epoch: [ 1671033474411 ] }
|
||||
- match: { hits.hits.0.fields.rtf_search: [ "2022-12-14" ] }
|
||||
|
||||
---
|
||||
"Query search time rtf with on_script_error fail":
|
||||
- do:
|
||||
catch: /type=script_exception, reason=runtime error/
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query:
|
||||
range:
|
||||
rtf_search:
|
||||
gte: "2022-12-14"
|
||||
fields: [ millis_since_epoch, rtf_search ]
|
||||
runtime_mappings:
|
||||
rtf_search:
|
||||
type: date
|
||||
format: yyyy-MM-dd
|
||||
script: |
|
||||
if(doc['millis_since_epoch'].value < 0) throw new Exception("date before 1970");
|
||||
emit(doc['millis_since_epoch'].value);
|
||||
on_script_error: fail
|
|
@ -0,0 +1,177 @@
|
|||
---
|
||||
setup:
|
||||
- do:
|
||||
indices.create:
|
||||
index: testindex
|
||||
body:
|
||||
settings:
|
||||
number_of_shards: 1
|
||||
number_of_replicas: 0
|
||||
mappings:
|
||||
runtime:
|
||||
rtf:
|
||||
type: ip
|
||||
script: |
|
||||
if(doc['ip_string'].value.length() <= 0) throw new Exception("empty");
|
||||
emit(doc['ip_string'].value);
|
||||
on_script_error: continue
|
||||
rtf_strict_error:
|
||||
type: ip
|
||||
script: |
|
||||
if(doc['ip_string'].value.length() <= 0) throw new Exception("empty");
|
||||
emit(doc['ip_string'].value);
|
||||
on_script_error: fail
|
||||
properties:
|
||||
ip_string:
|
||||
type: keyword
|
||||
|
||||
- do:
|
||||
bulk:
|
||||
index: testindex
|
||||
refresh: true
|
||||
body: |
|
||||
{"index":{}}
|
||||
{"ip_string": "192.68.0.1"}
|
||||
{"index":{}}
|
||||
{"ip_string": ""}
|
||||
|
||||
---
|
||||
"Query rtf with on_script_error continue":
|
||||
- do:
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query:
|
||||
term:
|
||||
rtf:
|
||||
192.68.0.1
|
||||
fields: [ ip_string, rtf ]
|
||||
- match: { hits.total.value: 1 }
|
||||
- match: { hits.hits.0.fields.ip_string: [ "192.68.0.1" ] }
|
||||
- match: { hits.hits.0.fields.rtf: [ 192.68.0.1 ] }
|
||||
|
||||
---
|
||||
"Query rtf with on_script_error fail":
|
||||
- do:
|
||||
catch: /type=script_exception, reason=runtime error/
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query:
|
||||
term:
|
||||
rtf_strict_error: 192.68.0.1
|
||||
fields: [ ip_string, rtf_strict_error ]
|
||||
|
||||
---
|
||||
"Aggregate on rtf with on_script_error continue":
|
||||
- do:
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
aggs:
|
||||
rtf:
|
||||
terms:
|
||||
field: rtf
|
||||
- length: { aggregations.rtf.buckets: 1 }
|
||||
- match: { aggregations.rtf.buckets.0.key: 192.68.0.1 }
|
||||
|
||||
---
|
||||
"Aggregate on rtf with on_script_error fail":
|
||||
- do:
|
||||
catch: /type=script_exception, reason=runtime error/
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
aggs:
|
||||
rtf:
|
||||
terms:
|
||||
field: rtf_strict_error
|
||||
|
||||
---
|
||||
"Fields retrieval with ignoring error":
|
||||
- do:
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query: { match_all: { } }
|
||||
fields: [ ip_string, rtf ]
|
||||
- match: { hits.total.value: 2 }
|
||||
- match: { hits.hits.0.fields.ip_string: [ "192.68.0.1" ] }
|
||||
- match: { hits.hits.0.fields.rtf: [ "192.68.0.1" ] }
|
||||
- match: { hits.hits.1.fields.ip_string: [ "" ] }
|
||||
- is_false: hits.hits.1.fields.rtf
|
||||
|
||||
---
|
||||
"Fields retrieval with failing on error":
|
||||
- do:
|
||||
catch: /type=script_exception, reason=runtime error/
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query: { match_all: { } }
|
||||
fields: [ ip_string, rtf_strict_error ]
|
||||
|
||||
---
|
||||
"Sorting with ignoring error":
|
||||
- do:
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query: { match_all: { } }
|
||||
fields: [ ip_string ]
|
||||
sort: rtf
|
||||
- match: { hits.total.value: 2 }
|
||||
- match: { hits.hits.0.fields.ip_string: [ "192.68.0.1" ] }
|
||||
- match: { hits.hits.1.fields.ip_string: [ "" ] }
|
||||
|
||||
---
|
||||
"Sorting with with failing on error":
|
||||
- do:
|
||||
catch: /type=script_exception, reason=runtime error/
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query: { match_all: { } }
|
||||
fields: [ ip_string ]
|
||||
sort: rtf_strict_error
|
||||
|
||||
---
|
||||
"Query search time rtf with on_script_error continue":
|
||||
- do:
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query:
|
||||
match:
|
||||
rtf_search: "192.68.0.1"
|
||||
fields: [ ip_string, rtf_search ]
|
||||
runtime_mappings:
|
||||
rtf_search:
|
||||
type: ip
|
||||
script: |
|
||||
if(doc['ip_string'].value.length() <= 0) throw new Exception("empty");
|
||||
emit(doc['ip_string'].value);
|
||||
on_script_error: continue
|
||||
|
||||
- match: { hits.total.value: 1 }
|
||||
- match: { hits.hits.0.fields.ip_string: [ "192.68.0.1" ] }
|
||||
- match: { hits.hits.0.fields.rtf_search: [ "192.68.0.1" ] }
|
||||
|
||||
---
|
||||
"Query search time rtf with on_script_error fail":
|
||||
- do:
|
||||
catch: /type=script_exception, reason=runtime error/
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query:
|
||||
match:
|
||||
rtf_search: "192.68.0.1"
|
||||
fields: [ ip_string, rtf_search ]
|
||||
runtime_mappings:
|
||||
rtf_search:
|
||||
type: ip
|
||||
script: |
|
||||
if(doc['ip_string'].value.length() <= 0) throw new Exception("empty");
|
||||
emit(doc['ip_string'].value);
|
||||
on_script_error: fail
|
|
@ -0,0 +1,184 @@
|
|||
---
|
||||
setup:
|
||||
- do:
|
||||
indices.create:
|
||||
index: testindex
|
||||
body:
|
||||
settings:
|
||||
number_of_shards: 1
|
||||
number_of_replicas: 0
|
||||
mappings:
|
||||
runtime:
|
||||
rtf:
|
||||
type: boolean
|
||||
script: |
|
||||
if(doc['age'].value < 0) throw new Exception("invalid age");
|
||||
emit(doc['age'].value >= 18);
|
||||
on_script_error: continue
|
||||
rtf_strict_error:
|
||||
type: boolean
|
||||
script: |
|
||||
if(doc['age'].value <= 0) throw new Exception("invalid age");
|
||||
emit(doc['age'].value >=18);
|
||||
on_script_error: fail
|
||||
properties:
|
||||
age:
|
||||
type: integer
|
||||
|
||||
- do:
|
||||
bulk:
|
||||
index: testindex
|
||||
refresh: true
|
||||
body: |
|
||||
{"index":{}}
|
||||
{"age": 14}
|
||||
{"index":{}}
|
||||
{"age": 20}
|
||||
{"index":{}}
|
||||
{"age": -1}
|
||||
|
||||
---
|
||||
"Query rtf with on_script_error continue":
|
||||
- do:
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query:
|
||||
match:
|
||||
rtf:
|
||||
true
|
||||
fields: [ age, rtf ]
|
||||
- match: { hits.total.value: 1 }
|
||||
- match: { hits.hits.0.fields.age: [ 20 ] }
|
||||
- match: { hits.hits.0.fields.rtf: [ true ] }
|
||||
|
||||
---
|
||||
"Query rtf with on_script_error fail":
|
||||
- do:
|
||||
catch: /type=script_exception, reason=runtime error/
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query:
|
||||
match:
|
||||
rtf_strict_error: true
|
||||
fields: [ age, rtf_strict_error ]
|
||||
|
||||
---
|
||||
"Aggregate on rtf with on_script_error continue":
|
||||
- do:
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
aggs:
|
||||
rtf:
|
||||
terms:
|
||||
field: rtf
|
||||
order: { "_key": "asc" }
|
||||
- length: { aggregations.rtf.buckets: 2 }
|
||||
- match: { aggregations.rtf.buckets.0.key_as_string: "false" }
|
||||
- match: { aggregations.rtf.buckets.1.key_as_string: "true" }
|
||||
---
|
||||
"Aggregate on rtf with on_script_error fail":
|
||||
- do:
|
||||
catch: /type=script_exception, reason=runtime error/
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
aggs:
|
||||
rtf:
|
||||
terms:
|
||||
field: rtf_strict_error
|
||||
|
||||
---
|
||||
"Fields retrieval with ignoring error":
|
||||
- do:
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query: { match_all: { } }
|
||||
fields: [ age, rtf ]
|
||||
sort: { "age": "desc" }
|
||||
- match: { hits.total.value: 3 }
|
||||
- match: { hits.hits.0.fields.age: [ 20 ] }
|
||||
- match: { hits.hits.0.fields.rtf: [ true ] }
|
||||
- match: { hits.hits.1.fields.age: [ 14 ] }
|
||||
- match: { hits.hits.1.fields.rtf: [ false ] }
|
||||
- match: { hits.hits.2.fields.age: [ -1 ] }
|
||||
- is_false: hits.hits.2.fields.rtf
|
||||
|
||||
---
|
||||
"Fields retrieval with failing on error":
|
||||
- do:
|
||||
catch: /type=script_exception, reason=runtime error/
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query: { match_all: { } }
|
||||
fields: [ age, rtf_strict_error ]
|
||||
|
||||
---
|
||||
"Sorting with ignoring error":
|
||||
- do:
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query: { match_all: { } }
|
||||
fields: [ age ]
|
||||
sort: rtf
|
||||
- match: { hits.total.value: 3 }
|
||||
- match: { hits.hits.0.fields.age: [ 14 ] }
|
||||
- match: { hits.hits.1.fields.age: [ 20 ] }
|
||||
- match: { hits.hits.2.fields.age: [ -1 ] }
|
||||
|
||||
---
|
||||
"Sorting with with failing on error":
|
||||
- do:
|
||||
catch: /type=script_exception, reason=runtime error/
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query: { match_all: { } }
|
||||
fields: [ age ]
|
||||
sort: rtf_strict_error
|
||||
|
||||
---
|
||||
"Query search time rtf with on_script_error continue":
|
||||
- do:
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query:
|
||||
match:
|
||||
rtf_search: true
|
||||
fields: [ age, rtf_search ]
|
||||
runtime_mappings:
|
||||
rtf_search:
|
||||
type: boolean
|
||||
script: |
|
||||
if(doc['age'].value < 0) throw new Exception("invalid age");
|
||||
emit(doc['age'].value >= 18);
|
||||
on_script_error: continue
|
||||
|
||||
- match: { hits.total.value: 1 }
|
||||
- match: { hits.hits.0.fields.age: [ 20 ] }
|
||||
- match: { hits.hits.0.fields.rtf_search: [ true ] }
|
||||
|
||||
---
|
||||
"Query search time rtf with on_script_error fail":
|
||||
- do:
|
||||
catch: /type=script_exception, reason=runtime error/
|
||||
search:
|
||||
index: testindex
|
||||
body:
|
||||
query:
|
||||
match:
|
||||
rtf_search: true
|
||||
fields: [ age, rtf_search ]
|
||||
runtime_mappings:
|
||||
rtf_search:
|
||||
type: boolean
|
||||
script: |
|
||||
if(doc['age'].value < 0) throw new Exception("invalid age");
|
||||
emit(doc['age'].value >= 18);
|
||||
on_script_error: fail
|
Loading…
Add table
Add a link
Reference in a new issue