Skip to content

Add 'lookup' as valid index mode for ES|QL lookup joins#936

Merged
jsoriano merged 41 commits into
mainfrom
add-lookup-index-mode
Aug 25, 2025
Merged

Add 'lookup' as valid index mode for ES|QL lookup joins#936
jsoriano merged 41 commits into
mainfrom
add-lookup-index-mode

Conversation

@JohannesMahne

@JohannesMahne JohannesMahne commented Jul 25, 2025

Copy link
Copy Markdown
Contributor

What does this PR do?

It adds lookup as a valid value for index mode, so that an index created by an integration can be a lookup index, to be used in a ES|QL LOOKUP JOIN.

Why is it important?

Chargeback integration (Draft integration - PR raised) needs.

Checklist

Related issues

@JohannesMahne JohannesMahne marked this pull request as ready for review July 25, 2025 10:07
@JohannesMahne JohannesMahne requested a review from a team as a code owner July 25, 2025 10:07
@kpollich

Copy link
Copy Markdown
Member

I have added test packages to test/packages that prove my change is effective.

We'll need tests to validate this I think. I'm not sure if Fleet will just take any value from index.mode of it we limit the modes on the Kibana side as well.

@jsoriano jsoriano left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We would need some test package to include this, ideally also in compliance, so this is tested with an actual kibana.

- "lookup" # Enables ES|QL LOOKUP JOIN https://www.elastic.co/docs/reference/query-languages/esql/esql-lookup-join
examples:
- "time_series"
- "lookup"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We will need a patch below under versions to remove this from previous versions.

Comment thread spec/changelog.yml Outdated
## This file documents changes in the package specification. It is NOT a package specification file.
## Newer entries go at the bottom of each in-development version.
##
- version: 3.6.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This change would release a 3.6.0 version, we need a -next suffix. Also, this change could be released in 3.4.2, or 3.5.0, depending if it needs explicit support in Fleet or not.

If this doesn't require explicit support in Fleet we could include this in 3.4.2-next. If it does, we could include it in 3.5.0-next.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As I do not think it needs explicit Fleet support, I am going for 3.4.2-next

@JohannesMahne

Copy link
Copy Markdown
Contributor Author

We would need some test package to include this, ideally also in compliance, so this is tested with an actual kibana.

@jsoriano - this is my first change... How would I test against a real kibana? Can you guide me with this?

I did all the changes as suggested/requested, and also added test data - which should work.

@jsoriano

jsoriano commented Jul 25, 2025

Copy link
Copy Markdown
Contributor

We would need some test package to include this, ideally also in compliance, so this is tested with an actual kibana.

@jsoriano - this is my first change... How would I test against a real kibana? Can you guide me with this?

Sure, now that you have a test package you could start by adding a feature file to compliance/features/esql.feature, something like this:

Feature: ES|QL
  Features related to ES|QL

  @3.4.2
  Scenario: Installer leverages lookup index mode
   Given the "good_lookup_index" package is installed
     And a policy is created with "good_lookup_index" package and "0.1.4" version
    Then index template "good_lookup_index.foo" is configured for "lookup index mode"

Then you would need to modify the indexTemplateIsConfiguredFor to support this new "lookup index mode" configuration check, or you can leave it by now as pending, but we will need to implement it before releasing 3.4.2.

If you want to try locally, you can run the compliance tests with elastic-package:

elastic-package stack up -v -d --version 9.1.0-SNAPSHOT
eval $(elastic-package stack shellinit)
TEST_SPEC_FEATURES=features/esql.feature TEST_SPEC_VERSION=3.4.2 make -C compliance/ test

@jsoriano jsoriano left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is looking good, thanks for adding the test case.

Comment thread spec/integration/data_stream/manifest.spec.yml Outdated

@jsoriano jsoriano Jul 25, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You would need to add this package to the list of packages in code/go/pkg/validator/validator_test.go, so it is actually tested.

@JohannesMahne

Copy link
Copy Markdown
Contributor Author

I had to update the spec to add the index mode to elasticsearch_index_template.
I also updated indextemplate.go in compliance to add the expected test case.
I had to adjust the test data to be better.

I ran the test, and in the Kibana logs I see the package loaded,

2025-07-26 08:12:08 [2025-07-26T06:12:08.643+00:00][DEBUG][plugins.fleet] Found previous transform references:
2025-07-26 08:12:08  [{"id":"logs-good_lookup_index.foo-default-0.1.0","type":"transform","deferred":false,"version":"0.1.0"}]
2025-07-26 08:12:08 [2025-07-26T06:12:08.921+00:00][DEBUG][plugins.fleet] Created api_key name: good_lookup_index-0.1.4-transform-by-elastic
2025-07-26 08:12:08 [2025-07-26T06:12:08.921+00:00][INFO ][plugins.fleet] Deleting currently installed transform ids logs-good_lookup_index.foo-default-0.1.0
2025-07-26 08:12:09 [2025-07-26T06:12:09.056+00:00][INFO ][plugins.fleet] Deleted: logs-good_lookup_index.foo-default-0.1.0
2025-07-26 08:12:09 [2025-07-26T06:12:09.105+00:00][DEBUG][plugins.fleet] Created transform: logs-good_lookup_index.foo-default-0.1.0
2025-07-26 08:12:09 [2025-07-26T06:12:09.189+00:00][DEBUG][plugins.fleet] Started transform: logs-good_lookup_index.foo-default-0.1.0
2025-07-26 08:12:09 [2025-07-26T06:12:09.207+00:00][DEBUG][plugins.fleet] Executed state: install_transforms with status: success - nextState: delete_previous_pipelines
2025-07-26 08:12:09 [2025-07-26T06:12:09.207+00:00][DEBUG][plugins.fleet] Current state delete_previous_pipelines: running transition stepDeletePreviousPipelines
2025-07-26 08:12:09 [2025-07-26T06:12:09.207+00:00][DEBUG][plugins.fleet] Executed state: delete_previous_pipelines with status: success - nextState: save_archive_entries_from_assets_map
2025-07-26 08:12:09 [2025-07-26T06:12:09.207+00:00][DEBUG][plugins.fleet] Current state save_archive_entries_from_assets_map: running transition stepSaveArchiveEntries
2025-07-26 08:12:09 [2025-07-26T06:12:09.217+00:00][DEBUG][plugins.fleet] Executed state: save_archive_entries_from_assets_map with status: success - nextState: resolve_kibana_promise
2025-07-26 08:12:09 [2025-07-26T06:12:09.217+00:00][DEBUG][plugins.fleet] Current state resolve_kibana_promise: running transition stepResolveKibanaPromise
2025-07-26 08:12:09 [2025-07-26T06:12:09.217+00:00][DEBUG][plugins.fleet] Executed state: resolve_kibana_promise with status: success - nextState: update_so
2025-07-26 08:12:09 [2025-07-26T06:12:09.217+00:00][DEBUG][plugins.fleet] Current state update_so: running transition stepSaveSystemObject
2025-07-26 08:12:09 [2025-07-26T06:12:09.593+00:00][DEBUG][plugins.fleet] Package install - Install status installed
2025-07-26 08:12:09 [2025-07-26T06:12:09.594+00:00][DEBUG][plugins.fleet] Install status installed - Installation complete!
2025-07-26 08:12:09 [2025-07-26T06:12:09.594+00:00][DEBUG][plugins.fleet] Executed state: update_so with status: success - nextState: end
2025-07-26 08:12:09 [2025-07-26T06:12:09.594+00:00][DEBUG][plugins.fleet] Removing old assets from previous versions of good_lookup_index

but it then tries to do stuff with .logs-endpoint.actions-default which is totally irrelevant and not related to the feature I am testing.

2025-07-26 08:12:09 [2025-07-26T06:12:09.795+00:00][DEBUG][plugins.fleet.AgentPolicyService.getByIds] returning [1] agent policies
2025-07-26 08:12:10 [2025-07-26T06:12:10.651+00:00][DEBUG][plugins.fleet.PackagePolicyClient.runPostDeleteExternalCallbacks] Running [3] external callbacks
2025-07-26 08:12:10 [2025-07-26T06:12:10.663+00:00][DEBUG][plugins.fleet.PackagePolicyClient.runPostDeleteExternalCallbacks] The following external callback threw error:
2025-07-26 08:12:10 Attempt to create index [.logs-endpoint.actions-default] failed with: illegal_argument_exception
2025-07-26 08:12:10     Root causes:
2025-07-26 08:12:10             illegal_argument_exception: no matching index template found for data stream [.logs-endpoint.actions-default]
2025-07-26 08:12:10 ResponseActionsClientError: Attempt to create index [.logs-endpoint.actions-default] failed with: illegal_argument_exception
2025-07-26 08:12:10     Root causes:
2025-07-26 08:12:10             illegal_argument_exception: no matching index template found for data stream [.logs-endpoint.actions-default]

I was digging into the Kibana logs, as I got this output from testing the feature:

johannesmahne@Johanness-MB-M1-Pro package-spec % TEST_SPEC_FEATURES=features/esql.feature TEST_SPEC_VERSION=3.4.2 make -C compliance/ test
=== RUN   TestSpecCompliance
Feature: ES|QL
  Features related to ES|QL
=== RUN   TestSpecCompliance/Installer_leverages_lookup_index_mode
elastic-package has been installed.
2025/07/26 08:12:07  WARN reading version file failed: open /var/folders/z2/dfrlcd_92nb_xc8qlm19kqjc0000gn/T/elastic-package-XXX3040961584/.elastic-package/latestVersion: no such file or directory
2025/07/26 08:12:07  INFO New version is available - v0.113.0. Download from: https://github.com/elastic/elastic-package/releases/tag/v0.113.0
2025/07/26 08:12:07  INFO License text found in "/Users/johannesmahne/Elastic/Product/package-spec/LICENSE.txt" will be included in package

  Scenario: Installer leverages lookup index mode                                     # features/esql.feature:5
    Given the "good_lookup_index" package is installed                                # compliance_test.go:85 -> github.com/elastic/package-spec/compliance.thePackageIsInstalled
    And a policy is created with "good_lookup_index" package and "0.1.4" version      # compliance_test.go:137 -> github.com/elastic/package-spec/compliance.aPolicyIsCreatedWithPackageAndVersion
    Then index template "good_lookup_index.foo" is configured for "lookup index mode" # compliance_test.go:208 -> github.com/elastic/package-spec/compliance.indexTemplateIsConfiguredFor
    HTTP status code 400
    suite.go:634: HTTP status code 400

--- Failed steps:

  Scenario: Installer leverages lookup index mode # features/esql.feature:5
    Then index template "good_lookup_index.foo" is configured for "lookup index mode" # features/esql.feature:8
      Error: HTTP status code 400


1 scenarios (1 failed)
3 steps (2 passed, 1 failed)
13.064695458s
=== NAME  TestSpecCompliance
    compliance_test.go:52: target deployment doesn't comply with Package Spec 3.4.2
--- FAIL: TestSpecCompliance (13.07s)
    --- FAIL: TestSpecCompliance/Installer_leverages_lookup_index_mode (13.06s)
FAIL
FAIL    github.com/elastic/package-spec/compliance      13.517s
FAIL
make: *** [test] Error 1

Inside Kibana I see the transform:

Screenshot 2025-07-26 at 08 19 39

I see the new index template:
Screenshot 2025-07-26 at 08 21 07

Screenshot 2025-07-26 at 08 21 38

Would you be able to point me into the right direction for debugging this?

@JohannesMahne

JohannesMahne commented Jul 26, 2025

Copy link
Copy Markdown
Contributor Author

Also see the actual index:
Screenshot 2025-07-26 at 08 37 41

And it is working as lookup index:

Screenshot 2025-07-26 at 08 42 02

@JohannesMahne JohannesMahne requested a review from jsoriano July 28, 2025 11:14
Comment thread spec/changelog.yml Outdated
changes:
- description: Add support for lookup indices.
type: enhancement
link: https://github.com/elastic/package-spec/pull/936

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please move it below 3.5.0-next.

Comment thread spec/changelog.yml
Comment on lines +235 to +243
mode:
description: >
Mode of the index, can be `standard`, `time_series` or `lookup`.
The `lookup` mode is used for data streams that are used as lookup indices.
type: string
enum:
- standard
- time_series
- lookup

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We have the other index_mode property as an indication to handle time series mode in a different way. Would it be possible to keep using this setting only?

Suggested change
mode:
description: >
Mode of the index, can be `standard`, `time_series` or `lookup`.
The `lookup` mode is used for data streams that are used as lookup indices.
type: string
enum:
- standard
- time_series
- lookup

type: string
enum:
- "time_series" # Enables time series data streams https://www.elastic.co/guide/en/elasticsearch/reference/master/tsds.html
- "lookup" # Enables ES|QL LOOKUP JOIN https://www.elastic.co/docs/reference/query-languages/esql/esql-lookup-join

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you test if setting the index mode with this setting works?

Comment on lines +3 to +5
settings:
index:
mode: "lookup" No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this feature only intended for transforms? If it is, we could maybe add this only to transforms. If it isn't could you add the setting to the data stream manifest?

Comment thread compliance/features/esql.feature Outdated
@JohannesMahne JohannesMahne force-pushed the add-lookup-index-mode branch from 8f9025e to 89fc4a4 Compare July 28, 2025 14:59
…Removed the lookup config from streams definition, and added it to the elasticsearch_index_template definition. Updated the patch. In the transform spec I had to use the normal index_template but add the definition of the index.mode.
@JohannesMahne

JohannesMahne commented Jul 29, 2025

Copy link
Copy Markdown
Contributor Author

@jsoriano - I reviewed all your comments and was able to resolve most of them. The definition of the lookup mode, it seems, needs to be on the elasticsearch_index_template and not on the streams as I had it initially. I also saw that I have to explicitly mention it in the transform spec under destination_index_template.

Can you please have another look?


I also updated the feature flag, so the test are all going through well.

% TEST_SPEC_FEATURES=features/esql.feature TEST_SPEC_VERSION=3.4.2 make -C compliance/ test
=== RUN   TestSpecCompliance
Feature: ES|QL
  Features related to ES|QL
=== RUN   TestSpecCompliance/Installer_leverages_lookup_index_mode
elastic-package has been installed.
2025/07/29 08:08:51  WARN reading version file failed: open /var/folders/z2/dfrlcd_92nb_xc8qlm19kqjc0000gn/T/elastic-package-XXX2199700630/.elastic-package/latestVersion: no such file or directory
2025/07/29 08:08:51  INFO License text found in "/Users/johannesmahne/Elastic/Product/package-spec/LICENSE.txt" will be included in package

  Scenario: Installer leverages lookup index mode                                                   # features/esql.feature:5
    Given the "good_lookup_index" package is installed                                              # compliance_test.go:310 -> github.com/elastic/package-spec/compliance.thePackageIsInstalled
    And a policy is created with "good_lookup_index" package and "0.1.4" version                    # compliance_test.go:312 -> github.com/elastic/package-spec/compliance.aPolicyIsCreatedWithPackageAndVersion
    Then index template "logs-good_lookup_index.foo-template" is configured for "lookup index mode" # compliance_test.go:317 -> github.com/elastic/package-spec/compliance.indexTemplateIsConfiguredFor

1 scenarios (1 passed)
3 steps (3 passed)
14.780531666s
--- PASS: TestSpecCompliance (14.78s)
    --- PASS: TestSpecCompliance/Installer_leverages_lookup_index_mode (14.78s)
PASS
ok      github.com/elastic/package-spec/compliance      15.236s

@jsoriano jsoriano left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If this is only needed for transforms, we need to think how to add it without affecting data streams. Sadly I don't know how to do it without duplicating the definition for index templates 🤔

Also, we should not add another method to define time series data streams.

Comment thread spec/integration/data_stream/manifest.spec.yml Outdated
Comment thread spec/integration/elasticsearch/transform/manifest.spec.yml Outdated
description: Elasticsearch index template for the transform's destination index
$ref: "#/definitions/index_template"
required: false
allOf:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure if this is really merging both schemas.

JohannesMahne and others added 2 commits July 30, 2025 07:47
Co-authored-by: Jaime Soriano Pastor <jaime.soriano@elastic.co>
Co-authored-by: Jaime Soriano Pastor <jaime.soriano@elastic.co>
…dex. Also, fix the versions in changelog, as requested.
…earch.properties.index_mode. Data streams: properties.elasticsearch_index_template.properties.settings.properties.index.properties.mode.
@JohannesMahne

Copy link
Copy Markdown
Contributor Author

@jsoriano - I added the lookup index mode only on the transform, as discussed in slack.

% TEST_SPEC_FEATURES=features/esql.feature TEST_SPEC_VERSION=3.4.3 make -C compliance/ test
=== RUN   TestSpecCompliance
Feature: ES|QL
  Features related to ES|QL
=== RUN   TestSpecCompliance/Installer_leverages_lookup_index_mode
elastic-package has been installed.
2025/08/20 08:34:59  WARN reading version file failed: open /var/folders/z2/dfrlcd_92nb_xc8qlm19kqjc0000gn/T/elastic-package-XXX3979788865/.elastic-package/latestVersion: no such file or directory
2025/08/20 08:35:00  INFO License text found in "/Users/johannesmahne/Elastic/Product/package-spec/LICENSE.txt" will be included in package

  Scenario: Installer leverages lookup index mode                                                   # features/esql.feature:5
    Given the "good_lookup_index" package is installed                                              # compliance_test.go:310 -> github.com/elastic/package-spec/compliance.thePackageIsInstalled
    And a policy is created with "good_lookup_index" package and "0.1.4" version                    # compliance_test.go:312 -> github.com/elastic/package-spec/compliance.aPolicyIsCreatedWithPackageAndVersion
    Then index template "logs-good_lookup_index.foo-template" is configured for "lookup index mode" # compliance_test.go:317 -> github.com/elastic/package-spec/compliance.indexTemplateIsConfiguredFor

1 scenarios (1 passed)
3 steps (3 passed)
14.855733458s
--- PASS: TestSpecCompliance (14.86s)
    --- PASS: TestSpecCompliance/Installer_leverages_lookup_index_mode (14.86s)
PASS
ok      github.com/elastic/package-spec/compliance      15.331s

@JohannesMahne JohannesMahne requested a review from jsoriano August 20, 2025 07:29

@jsoriano jsoriano left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the latest changes to limit changes to lookup indexes in transforms.

I think current approach is fine because transforms are already different to data streams, and we don't get into having to support TSDB in transform indexes.

To be clear, this leaves elastic/elastic-package#2829 behind, we will have to address this as a separate effort. cc @Coler-e.

Comment thread spec/changelog.yml
Comment thread spec/integration/elasticsearch/transform/manifest.spec.yml Outdated
@JohannesMahne JohannesMahne requested a review from jsoriano August 22, 2025 12:51
@JohannesMahne

Copy link
Copy Markdown
Contributor Author

@jsoriano - I tested removing standard and all passed. Please check again. :)

@elasticmachine

Copy link
Copy Markdown

💚 Build Succeeded

History

@jsoriano jsoriano left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

@JohannesMahne

Copy link
Copy Markdown
Contributor Author

@jsoriano - Thank you for approving the PR. What is the process of getting this merged? I do not have authorization to do this.

type: object
additionalProperties: false
properties:
mode:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should probably add a patch so this is not used on packages with a format version older than 3.4. I will do this in a follow up.

@jsoriano jsoriano merged commit 23af223 into main Aug 25, 2025
3 checks passed
@jsoriano jsoriano deleted the add-lookup-index-mode branch August 25, 2025 14:56
@jsoriano jsoriano mentioned this pull request Aug 25, 2025
2 tasks
##
## Describes the specification for a transform's manifest.yml file
##
spec:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We have removed the spec level from this file, so we are effectively removing validation from here. Attempting to fix this in #964.

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.

9 participants