-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Count number of documents with at least one ignored field #109146
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
Open
salvatore-campagna
wants to merge
46
commits into
elastic:main
Choose a base branch
from
salvatore-campagna:feature/108092-docs-with-ignored-fields
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 14 commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
ea1d2c8
feature: count number of documents with at least one ignored field
salvatore-campagna 5b0bf9c
Update docs/changelog/109146.yaml
salvatore-campagna 0516fa7
Update docs/changelog/109146.yaml
salvatore-campagna b468362
fix: adding missing 'Logs' to changelog schema
salvatore-campagna 46571dd
fix: constructor invokation
salvatore-campagna 7419e0b
fix: constructor invokation
salvatore-campagna 4fffc73
docs: update docs stats page
salvatore-campagna 0d88613
fix: skip null check
salvatore-campagna 50911a7
fix: add missing docs_with_ignored_fields
salvatore-campagna 19e2bc2
fix: a few more tests
salvatore-campagna 0952941
Merge branch 'main' into feature/108092-docs-with-ignored-fields
salvatore-campagna 9ed9505
fix: update transport version id after main merge
salvatore-campagna aebeb19
fix: use -1 as init value
salvatore-campagna c9639d7
Merge branch 'main' into feature/108092-docs-with-ignored-fields
salvatore-campagna b0f61ae
note: souce only snapshot unsupported
salvatore-campagna 8c92be8
Revert "fix: use -1 as init value"
salvatore-campagna bb74c2f
nit: remove this
salvatore-campagna 4baab8a
fix: introduce sum_doc_freq_terms_ignored_field
salvatore-campagna 5e2475e
fix: add missing sum_doc_freq_terms_ignored_field
salvatore-campagna 9063532
fix: extract method
salvatore-campagna 9d44e50
fix: adjust error message
salvatore-campagna 789f27f
do, or do not, there is npo try
salvatore-campagna aa29fb7
fix: make ingored field stats optional
salvatore-campagna 14fd47c
fix: missing ignored field stats
salvatore-campagna 52d8628
fix: mssing boolean param
salvatore-campagna 88023d1
fix: writeVLong requires positive long values
salvatore-campagna 8e45c2a
fix: use positive and negative values
salvatore-campagna da184fa
fix: use object to collect ignored field stats
salvatore-campagna 7081c93
fix: default constructor, equals and hash code
salvatore-campagna bd4fe4a
nit: some code cleanup
salvatore-campagna 188ab53
Merge branch 'main' into feature/108092-docs-with-ignored-fields
salvatore-campagna 01fc479
fix: use a separate object for ignored field stats
salvatore-campagna 675a368
fix: boolean not required anymore
salvatore-campagna 33b943e
fix: use ignored field source when acquiring searcher
salvatore-campagna b4f4748
fix: restore unwanted changes
salvatore-campagna e656e7c
fix: reuse an already open searcher for searchable snapshot
salvatore-campagna d842108
fix: remove docs from cluster stats
salvatore-campagna 0ec7272
fix: make method names consistent
salvatore-campagna 2ca4842
fix: explicitly initialize value
salvatore-campagna c663ff5
nit: rename capability
salvatore-campagna 573377d
fix: remove unused code
salvatore-campagna bbb9cae
Merge branch 'main' into feature/108092-docs-with-ignored-fields
salvatore-campagna 4a6e586
docs: improve docs
salvatore-campagna 38da229
Merge branch 'main' into feature/108092-docs-with-ignored-fields
salvatore-campagna 2b795ae
Merge branch 'main' into feature/108092-docs-with-ignored-fields
salvatore-campagna 72e6935
Merge branch 'main' into feature/108092-docs-with-ignored-fields
salvatore-campagna 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
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,6 @@ | ||
pr: 109146 | ||
summary: Count number of documents with at least one ignored field | ||
area: Logs | ||
type: feature | ||
issues: | ||
- 108092 |
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
123 changes: 123 additions & 0 deletions
123
...pi-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.stats/110_ignored_field.yml
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,123 @@ | ||
--- | ||
"indices stats including documents with ignored fields": | ||
- requires: | ||
test_runner_features: [ capabilities ] | ||
capabilities: | ||
- method: GET | ||
path: /{index}/_stats | ||
capabilities: [ count_docs_with_ignored_fields ] | ||
reason: "Counting docs with ignored fields required" | ||
|
||
- do: | ||
indices.create: | ||
index: test1 | ||
body: | ||
settings: | ||
number_of_shards: 3 | ||
number_of_replicas: 0 | ||
mappings: | ||
properties: | ||
email: | ||
type: keyword | ||
ignore_above: 15 | ||
date_of_birth: | ||
type: date | ||
format: "dd-MM-yyyy" | ||
ignore_malformed: true | ||
ip_address: | ||
type: ip | ||
ignore_malformed: true | ||
|
||
- do: | ||
indices.create: | ||
index: test2 | ||
body: | ||
settings: | ||
number_of_shards: 3 | ||
number_of_replicas: 0 | ||
mappings: | ||
properties: | ||
email: | ||
type: keyword | ||
ignore_above: 15 | ||
date_of_birth: | ||
type: date | ||
format: "dd-MM-yyyy" | ||
ignore_malformed: true | ||
ip_address: | ||
type: ip | ||
ignore_malformed: true | ||
|
||
- do: | ||
indices.create: | ||
index: test3 | ||
body: | ||
settings: | ||
number_of_shards: 3 | ||
number_of_replicas: 0 | ||
mappings: | ||
properties: | ||
email: | ||
type: keyword | ||
ignore_above: 15 | ||
date_of_birth: | ||
type: date | ||
format: "dd-MM-yyyy" | ||
ignore_malformed: true | ||
ip_address: | ||
type: ip | ||
ignore_malformed: true | ||
|
||
- do: | ||
bulk: | ||
index: test1 | ||
refresh: true | ||
body: | ||
- { "index": { "_id": "001" } } | ||
- {"email": "[email protected]", "date_of_birth": "10-11-1992", "ip_address": "117.12.45.79" } | ||
- { "index": { "_id": "002" } } | ||
- { "email": "[email protected]", "date_of_birth": "12-04-1993", "ip_address": "178.22.231.24" } | ||
|
||
- do: | ||
bulk: | ||
index: test2 | ||
refresh: true | ||
body: | ||
- { "index": { "_id": "003" } } | ||
- { "email": "[email protected]", "date_of_birth": "09-02-1990", "ip_address": "117.12.45.79" } | ||
- { "index": { "_id": "004" } } | ||
- { "email": "[email protected]", "date_of_birth": "12-24-1991", "ip_address": "133.45.123.12" } | ||
|
||
- do: | ||
bulk: | ||
index: test3 | ||
refresh: false # document not flushed to Lucene segment | ||
body: | ||
- { "index": { "_id": "005" } } | ||
- { "email": "[email protected]", "date_of_birth": "04-05-1992", "ip_address": "123.77.18.488" } | ||
|
||
- do: | ||
indices.stats: | ||
index: test* | ||
metric: docs | ||
|
||
- match: { _all.primaries.docs.count: 4 } | ||
- match: { _all.primaries.docs.docs_with_ignored_fields: 2 } | ||
- match: { _all.total.docs.count: 4 } | ||
- match: { _all.total.docs.docs_with_ignored_fields: 2 } | ||
|
||
- match: { indices.test1.primaries.docs.count: 2 } | ||
- match: { indices.test1.primaries.docs.docs_with_ignored_fields: 0 } | ||
- match: { indices.test1.total.docs.count: 2 } | ||
- match: { indices.test1.total.docs.docs_with_ignored_fields: 0 } | ||
|
||
- match: { indices.test2.primaries.docs.count: 2 } | ||
- match: { indices.test2.primaries.docs.docs_with_ignored_fields: 2 } | ||
- match: { indices.test2.total.docs.count: 2 } | ||
- match: { indices.test2.total.docs.docs_with_ignored_fields: 2 } | ||
|
||
# Not refreshed | ||
- match: { indices.test3.primaries.docs.count: 0 } | ||
- match: { indices.test3.primaries.docs.docs_with_ignored_fields: 0 } | ||
- match: { indices.test3.total.docs.count: 0 } | ||
- match: { indices.test3.total.docs.docs_with_ignored_fields: 0 } |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,7 @@ | |
import org.elasticsearch.index.VersionType; | ||
import org.elasticsearch.index.mapper.DocumentParser; | ||
import org.elasticsearch.index.mapper.IdFieldMapper; | ||
import org.elasticsearch.index.mapper.IgnoredFieldMapper; | ||
import org.elasticsearch.index.mapper.LuceneDocument; | ||
import org.elasticsearch.index.mapper.Mapping; | ||
import org.elasticsearch.index.mapper.MappingLookup; | ||
|
@@ -215,6 +216,7 @@ protected final DocsStats docsStats(IndexReader indexReader) { | |
long numDocs = 0; | ||
long numDeletedDocs = 0; | ||
long sizeInBytes = 0; | ||
long docsWithIgnoredFields = 0; | ||
// we don't wait for a pending refreshes here since it's a stats call instead we mark it as accessed only which will cause | ||
// the next scheduled refresh to go through and refresh the stats as well | ||
for (LeafReaderContext readerContext : indexReader.leaves()) { | ||
|
@@ -228,8 +230,20 @@ protected final DocsStats docsStats(IndexReader indexReader) { | |
} catch (IOException e) { | ||
logger.trace(() -> "failed to get size for [" + info.info.name + "]", e); | ||
} | ||
docsWithIgnoredFields = tryGetNumberOfDocumentsWithIgnoredFields(readerContext); | ||
} | ||
return new DocsStats(numDocs, numDeletedDocs, sizeInBytes); | ||
return new DocsStats(numDocs, numDeletedDocs, sizeInBytes, docsWithIgnoredFields); | ||
} | ||
|
||
private long tryGetNumberOfDocumentsWithIgnoredFields(final LeafReaderContext readerContext) { | ||
try { | ||
return readerContext.reader().getSumDocFreq(IgnoredFieldMapper.NAME); | ||
} catch (IOException e) { | ||
logger.trace(() -> "IO error while getting the number of documents with ignored fields", e); | ||
} catch (UnsupportedOperationException e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This happens for |
||
logger.trace(() -> "Getting number of documents with ignored fields is not supported", e); | ||
} | ||
return 0; | ||
} | ||
|
||
/** | ||
|
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
18 changes: 18 additions & 0 deletions
18
...c/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesStatsCapabilities.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,18 @@ | ||
/* | ||
* 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 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 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.rest.action.admin.indices; | ||
|
||
import java.util.Set; | ||
|
||
public class RestIndicesStatsCapabilities { | ||
|
||
private static final String COUNT_DOCS_WITH_IGNORED_FIELDS = "count_docs_with_ignored_fields"; | ||
|
||
public static final Set<String> CAPABILITIES = Set.of(COUNT_DOCS_WITH_IGNORED_FIELDS); | ||
} |
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.
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.
Should this invoke
getDocCount()
instead? Which returns:Returns the number of documents that have at least one term for this field
, which matches more closely with the method name and what we are trying to include in the doc stats?