Skip to content

Commit 3a81990

Browse files
Add runtime_mappings support
1 parent 8fe3d0f commit 3a81990

File tree

5 files changed

+39
-3
lines changed

5 files changed

+39
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### New Features
66

7+
* [#887](https://github.com/toptal/chewy/pull/887): Add support [runtime_mappings](https://www.elastic.co/guide/en/elasticsearch/reference/current/runtime-search-request.html). ([@TakuyaKurimoto](https://github.com/TakuyaKurimoto))
78
### Changes
89

910
### Bugs Fixed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module Chewy
2+
module Search
3+
class Parameters
4+
# Just a standard hash storage. Nothing to see here.
5+
#
6+
# @see Chewy::Search::Parameters::HashStorage
7+
# @see Chewy::Search::Request#runtime_mappings
8+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/runtime-search-request.html
9+
class RuntimeMappings < Storage
10+
include HashStorage
11+
end
12+
end
13+
end
14+
end

lib/chewy/search/request.rb

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Request
2525
search_type preference limit offset terminate_after
2626
timeout min_score source stored_fields search_after
2727
load script_fields suggest aggs aggregations collapse none
28-
indices_boost rescore highlight total total_count
28+
indices_boost rescore highlight runtime_mappings total total_count
2929
total_entries indices types delete_all count exists?
3030
exist? find pluck scroll_batches scroll_hits
3131
scroll_results scroll_wrappers ignore_unavailable
@@ -645,7 +645,23 @@ def load(options = nil)
645645
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/highlighting.html
646646
# @param value [Hash]
647647
# @return [Chewy::Search::Request]
648-
%i[script_fields indices_boost rescore highlight].each do |name|
648+
#
649+
# @!method runtime_mappings(value)
650+
# Add a `runtime_mappings` part to the request. Further
651+
# call values are merged to the storage hash.
652+
#
653+
# @example
654+
# PlacesIndex
655+
# .runtime_mappings(field1: {type: "keyword", :script=>{:lang=>"painless", :source=>"emit('some script here')"}})
656+
# .runtime_mappings(field2: {type: "keyword", :script=>{:lang=>"painless", :source=>"emit('some script here')"}})
657+
# # => <PlacesIndex::Query {..., :body=>{:runtime_mappings=>{
658+
# # "field1"=>{:type=>"keyword", :script=>{:lang=>"painless", :source=>"emit('some script here')"}},
659+
# # "field2"=>{:type=>"keyword", :script=>{:lang=>"painless", :source=>"emit('some script here')"}}}}}>
660+
# @see Chewy::Search::Parameters::ScriptFields
661+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/runtime-search-request.html
662+
# @param value [Hash]
663+
# @return [Chewy::Search::Request]
664+
%i[script_fields indices_boost rescore highlight runtime_mappings].each do |name|
649665
define_method name do |value|
650666
modify(name) { update!(value) }
651667
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require 'chewy/search/parameters/hash_storage_examples'
2+
3+
describe Chewy::Search::Parameters::RuntimeMappings do
4+
it_behaves_like :hash_storage, :runtime_mappings
5+
end

spec/chewy/search/request_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@
284284
specify { expect { subject.stored_fields(:foo) }.not_to change { subject.render } }
285285
end
286286

287-
%i[script_fields highlight].each do |name|
287+
%i[script_fields highlight runtime_mappings].each do |name|
288288
describe "##{name}" do
289289
specify { expect(subject.send(name, foo: {bar: 42}).render[:body]).to include(name => {'foo' => {bar: 42}}) }
290290
specify do

0 commit comments

Comments
 (0)