sudo-suhas / elastic-builder

A Node.js implementation of the elasticsearch Query DSL :construction_worker:
https://elastic-builder.js.org
MIT License
508 stars 75 forks source link

Feat/Add support for runtime_mappings [Issue: #152] #196

Closed atreids closed 7 months ago

atreids commented 7 months ago

Issue:

resolves #152

Additional Author

Original PR was raised by @jmaitrehenry but appears to be abandoned. This PR attempts to complete implementation of this feature, based upon his original work.

Aim:

Add support for Elasticsearch runtime_mappings field, added in v7.11.0.

Usage:

const field = esb.runtimeField(
      'keyword',
      `emit(doc['sessionId'].value + '::' + doc['name'].value)`,
);
const reqBody = esb.requestBodySearch();
reqBody.runtimeMapping('sessionId-eventName', field);

Will generate query:

{
  "runtime_mappings": {
    "sessionId-eventName": {
      "type": "keyword",
      "script": {
        "source": "emit(doc['sessionId'].value + '::' + doc['name'].value)"
      }
    }
  }
}

Changes from original PR

sudo-suhas commented 7 months ago

Thanks again @atreids for the PR!

github-actions[bot] commented 7 months ago

:tada: This PR is included in version 2.28.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: