Skip to content

Commit 6a7cf31

Browse files
Add runtime_mappings support
1 parent 8fe3d0f commit 6a7cf31

5 files changed

Lines changed: 38 additions & 2 deletions

File tree

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: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: {script: {lang: 'painless', inline: 'some script here'}})
656+
# .runtime_mappings(field2: {script: {lang: 'painless', inline: '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)