Skip to content

Add runtime_mappings support#887

Open
TakuyaKurimoto wants to merge 1 commit intotoptal:masterfrom
TakuyaKurimoto:feature/add-runtime-mappings
Open

Add runtime_mappings support#887
TakuyaKurimoto wants to merge 1 commit intotoptal:masterfrom
TakuyaKurimoto:feature/add-runtime-mappings

Conversation

@TakuyaKurimoto
Copy link

@TakuyaKurimoto TakuyaKurimoto commented May 15, 2023

Hello.
One time I wanted to use runtime_mappings, but in chewy I had to write the following code because chewy does not support runtime_mappings .

q = HogeIndex.query({}).render
q[:body][:runtime_mappings] = {"field1"=>{type: 'keyword', :script=>{:lang=>"painless", :source=>"emit('some script here')"}}}
HogeIndex.client.search(body: q[:body])

This is a bit inconvenient, so I was wondering if you could support runtime_mappings in chewy as well?

If this code is merged, it will be possible to do something like the code below

CitiesIndex
  .runtime_mappings(
    field1: {
      type: 'keyword',
      :script=>{
        :lang=>"painless",
        :source=>"emit('some script here')"
      }
    }
  )
  .aggs(
    field1: {
      terms: {
        field: "field1"
      }
    }
  )

Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the changelog if the new code introduces user-observable changes. See changelog entry format for details.

@TakuyaKurimoto TakuyaKurimoto force-pushed the feature/add-runtime-mappings branch 3 times, most recently from 6a7cf31 to 3a81990 Compare May 15, 2023 16:09
@konalegi
Copy link

@TakuyaKurimoto Thanks for the PR! unfortunately I'm not familiar with the runtime mappings features, let me learn it and get back to you.

@TakuyaKurimoto
Copy link
Author

OK!
I'm sorry for bothering you.

@TakuyaKurimoto
Copy link
Author

@konalegi
sorry for bothering you. Any updates on that one?

@konalegi
Copy link

konalegi commented Oct 8, 2024

@TakuyaKurimoto Sorry, was extremely busy. Is this PR still relevant?

@TakuyaKurimoto
Copy link
Author

@konalegi
Thanks for getting back to me. The problem is still there, so I'd appreciate it if you could apply this patch.

@konalegi
Copy link

konalegi commented Oct 8, 2024

Cool, can you rebase and push latest changes so I can run CI?

@TakuyaKurimoto TakuyaKurimoto force-pushed the feature/add-runtime-mappings branch from 3a81990 to dd04e71 Compare October 8, 2024 14:18
@TakuyaKurimoto TakuyaKurimoto requested a review from a team as a code owner October 8, 2024 14:18
@TakuyaKurimoto
Copy link
Author

TakuyaKurimoto commented Oct 8, 2024

@konalegi
rebased! Please run CI.

@konalegi
Copy link

konalegi commented Oct 8, 2024

Everything is passing, let me get familiar with the topic, and I'll merge it.

@TakuyaKurimoto
Copy link
Author

Thank you!

@konalegi
Copy link

konalegi commented Oct 9, 2024

@TakuyaKurimoto looks good 👍 Although could you please add a couple of lines into documentation about this feature, no extensive doc is needed, just an example + reference to elastic doc, so people know that this feature exists.
Thanks!

@TakuyaKurimoto
Copy link
Author

@konalegi
Sorry, but which file are you referring to when you say "documentation"? Is it CHANGELOG.md?

@konalegi
Copy link

konalegi commented Oct 9, 2024

@TakuyaKurimoto Actually I'm about README.md

@TakuyaKurimoto TakuyaKurimoto force-pushed the feature/add-runtime-mappings branch 2 times, most recently from 693f689 to ef5d800 Compare October 10, 2024 12:29
@TakuyaKurimoto
Copy link
Author

@konalegi
I understand. I've added the document, so please check it.

@bbatsov
Copy link
Member

bbatsov commented Feb 25, 2026

Master has been updated with CI fixes and compatibility changes (#998) — we now target Ruby 3.2+ and Rails 7.2+. Could you rebase this PR on top of master so CI can run properly? Thanks!

@bbatsov
Copy link
Member

bbatsov commented Feb 25, 2026

Nice addition — runtime_mappings is a useful ES feature. The implementation looks straightforward.

Could you rebase onto current master? The branch is quite old (2+ years) and will need updating. Also please add a changelog entry.

@TakuyaKurimoto TakuyaKurimoto force-pushed the feature/add-runtime-mappings branch from ef5d800 to ce27b79 Compare February 26, 2026 15:07
@TakuyaKurimoto TakuyaKurimoto requested a review from a team as a code owner February 26, 2026 15:07
@TakuyaKurimoto
Copy link
Author

@bbatsov
I have rebased the branch onto the latest master and added the changelog entry. Please take another look.

Copy link
Member

@bbatsov bbatsov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! The implementation is clean and follows existing patterns well. A couple of things to address:

  1. Wrong @see reference — In lib/chewy/search/request.rb, the new runtime_mappings docblock has @see Chewy::Search::Parameters::ScriptFields but it should be @see Chewy::Search::Parameters::RuntimeMappings.

  2. Inconsistent hash syntax in the @example — The example mixes symbol rockets (:script=>) with modern hash syntax (type:). Would be cleaner to pick one style consistently.

Also, the branch is quite far behind master at this point — please rebase on top of the current master (and address the changelog conflict).

@TakuyaKurimoto TakuyaKurimoto force-pushed the feature/add-runtime-mappings branch from ce27b79 to b6f59a6 Compare March 16, 2026 13:27
@TakuyaKurimoto
Copy link
Author

TakuyaKurimoto commented Mar 16, 2026

@bbatsov
Thanks for your review!
I've addressed all the feedback.
Please take another look. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants