Skip to content

Conversation

@davidkyle
Copy link
Member

@davidkyle davidkyle commented Nov 30, 2020

This change adds runtime fields in search to the datafeed.

The DatafeedConfig has an optional section to defined search runtime fields

            "runtime_mappings" : {
                "rt_field_1": {
                    "type": "double",
                    "script": "emit(doc['some_field'].value * 100.0)"
                },
                "rt_field_2": {
                    "type": "double",
                    "script": "emit(doc['another_field'].value)"
                },

The actual configuration is just a loose Map<String, Object> as this is what SearchSourceBuilder uses. There is some validation on PUT that the map contents resemble a runtime_mappings configuration.

Datafeed preview and running a datafeed are not exactly the same. The checks in DatafeedJobValidator are not run in preview which means the check that the time field is not an RT field will not happen. We should discuss changing preview to exactly match the behaviour or running a datafeed.

There are some design decisions that the reviewer should know about:

  1. Configurations of jobs/datafeeds that use runtime_mappings to create the job time field will be rejected.
  2. RT fields do no work with v1 Rollup searches. If the datafeed is querying a rollup index it will not start if RT fields are used.
  3. RT fields in Cross Cluster Search require the remote cluster to be v7.11 or above. The datafeed will start and the search will fail in this case. It is not possible to check prior to starting the datafeed.

HLRC to follow, this change is big enough.

@davidkyle davidkyle marked this pull request as draft November 30, 2020 13:49
@davidkyle davidkyle marked this pull request as ready for review November 30, 2020 22:36
@elasticmachine
Copy link
Collaborator

Pinging @elastic/ml-core (:ml)

Copy link

@droberts195 droberts195 left a comment

Choose a reason for hiding this comment

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

Looks good.

I just had a few minor nits.

Choose a reason for hiding this comment

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

It might be better to say object instead of map in this error message, as the user reading the message is thinking of the JSON structure rather than the Java structure.

Copy link
Member Author

Choose a reason for hiding this comment

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

map is consistent with the language used here

throw new MapperParsingException("Expected map for runtime field [" + fieldName + "] definition but got a "

Choose a reason for hiding this comment

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

It's still wrong - the word "map" does not appear anywhere in this page: https://www.json.org/json-en.html

It sounds like there is going to be a separate PR to correct this throughout the runtime fields code though, so all instances can be fixed in one go.

Copy link

@droberts195 droberts195 left a comment

Choose a reason for hiding this comment

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

LGTM

@davidkyle davidkyle merged commit ab08631 into elastic:master Dec 2, 2020
davidkyle added a commit to davidkyle/elasticsearch that referenced this pull request Dec 2, 2020
Adds the runtime_mappings section to DatafeedConfig to define runtime fields.
The runtime fields are then passed through to datafeed searches
@davidkyle davidkyle deleted the rt-search-df branch December 3, 2020 09:31
davidkyle added a commit that referenced this pull request Dec 8, 2020
…65759)

Adds the runtime_mappings section to DatafeedConfig to define runtime fields.
The runtime fields are then passed through to datafeed searches
davidkyle added a commit that referenced this pull request Dec 8, 2020
davidkyle added a commit to davidkyle/elasticsearch that referenced this pull request Dec 8, 2020
davidkyle added a commit that referenced this pull request Dec 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants