-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add block loader from stored field and source for ip field #126644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5ad383f
wip
lkts 6770b79
Add block loader from stored field and source for ip field
lkts 73525cd
Update docs/changelog/126644.yaml
lkts 0f11bf7
fix test and add capability
lkts 2b77823
Merge branch 'main' into synthetic_source_block_loader_ip
lkts 074ae5d
fix
lkts 0d97213
skip compatibility
lkts bf1ae8e
support FieldExtractPreference.STORED
lkts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pr: 126644 | ||
| summary: Add block loader from stored field and source for ip field | ||
| area: Mapping | ||
| type: enhancement | ||
| issues: [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
server/src/test/java/org/elasticsearch/index/mapper/blockloader/IpFieldBlockLoaderTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| package org.elasticsearch.index.mapper.blockloader; | ||
|
|
||
| import org.apache.lucene.document.InetAddressPoint; | ||
| import org.apache.lucene.util.BytesRef; | ||
| import org.elasticsearch.common.network.InetAddresses; | ||
| import org.elasticsearch.index.mapper.BlockLoaderTestCase; | ||
| import org.elasticsearch.index.mapper.MappedFieldType; | ||
| import org.elasticsearch.logsdb.datageneration.FieldType; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
|
|
||
| public class IpFieldBlockLoaderTests extends BlockLoaderTestCase { | ||
| public IpFieldBlockLoaderTests(Params params) { | ||
| super(FieldType.IP.toString(), params); | ||
| } | ||
|
|
||
| @Override | ||
| @SuppressWarnings("unchecked") | ||
| protected Object expected(Map<String, Object> fieldMapping, Object value, TestContext testContext) { | ||
| var rawNullValue = (String) fieldMapping.get("null_value"); | ||
| BytesRef nullValue = convert(rawNullValue, null); | ||
|
|
||
| if (value == null) { | ||
| return convert(null, nullValue); | ||
| } | ||
| if (value instanceof String s) { | ||
| return convert(s, nullValue); | ||
| } | ||
|
|
||
| boolean hasDocValues = hasDocValues(fieldMapping, true); | ||
| boolean useDocValues = params.preference() == MappedFieldType.FieldExtractPreference.NONE | ||
| || params.preference() == MappedFieldType.FieldExtractPreference.DOC_VALUES | ||
| || params.syntheticSource(); | ||
| if (hasDocValues && useDocValues) { | ||
| var resultList = ((List<String>) value).stream() | ||
| .map(v -> convert(v, nullValue)) | ||
| .filter(Objects::nonNull) | ||
| .distinct() | ||
| .sorted() | ||
| .toList(); | ||
| return maybeFoldList(resultList); | ||
| } | ||
|
|
||
| // field is stored or using source | ||
| var resultList = ((List<String>) value).stream().map(v -> convert(v, nullValue)).filter(Objects::nonNull).toList(); | ||
| return maybeFoldList(resultList); | ||
| } | ||
|
|
||
| private static BytesRef convert(Object value, BytesRef nullValue) { | ||
| if (value == null) { | ||
| return nullValue; | ||
| } | ||
|
|
||
| if (value instanceof String s) { | ||
| try { | ||
| var address = InetAddresses.forString(s); | ||
| return new BytesRef(InetAddressPoint.encode(address)); | ||
| } catch (Exception ex) { | ||
| // malformed | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this because it was very easy to do. I am not sure if there are any cases when this is not beneficial? Some existing implementations don't bother and just go straight to loading from source.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 - seems easy to just do in this pr.