Skip to content
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

Adding aggregations support for the _ignored field #101373

Merged
merged 123 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
123 commits
Select commit Hold shift + click to select a range
50d1ffb
Adding aggregations support for the _ignored field
eyalkoren Oct 26, 2023
737fbb2
Update docs/changelog/101373.yaml
eyalkoren Oct 26, 2023
ace155a
spotless
eyalkoren Oct 26, 2023
e698cc1
Merge remote-tracking branch 'eyalkoren/ignore_field_aggs' into ignor…
eyalkoren Oct 26, 2023
5e3f6ec
Adjust tests
eyalkoren Oct 27, 2023
ef9ce62
Merge remote-tracking branch 'upstream/main' into ignore_field_aggs
eyalkoren Oct 30, 2023
c34dc4b
Add exists query using doc_values
eyalkoren Oct 31, 2023
aa9cdec
Improve error message for unsupported aggs
eyalkoren Oct 31, 2023
2e03324
ohh come on
eyalkoren Nov 1, 2023
8bc6582
Merge remote-tracking branch 'upstream/main' into ignore_field_aggs
eyalkoren Nov 27, 2023
873a34f
WIP: making field not stored
eyalkoren Nov 29, 2023
904694b
Merge branch 'main' into ignore_field_aggs
salvatore-campagna Feb 5, 2024
aba9ff6
fix: _ignored field in meta field list
salvatore-campagna Feb 6, 2024
a316a4d
fix: make _ignored field stored
salvatore-campagna Feb 6, 2024
f6c4ad2
fix: do not use a mock for SearchExecutionContext
salvatore-campagna Feb 6, 2024
53d374e
fix: decrement reference count for response objects
salvatore-campagna Feb 6, 2024
f78532d
fix: include a new sub-fetch phase fetching the _ignored field from d…
salvatore-campagna Feb 8, 2024
1256646
fix: index the _ignored field
salvatore-campagna Feb 8, 2024
47cf96a
fix: remove fetch phase if stored fields are disabled
salvatore-campagna Feb 8, 2024
3c5d42e
fix: introduce the new phase in yaml tests
salvatore-campagna Feb 9, 2024
fea357c
Merge branch 'main' into ignore_field_aggs
salvatore-campagna Feb 9, 2024
6e80788
fix: include _ignored field as stored for backward compatibility
salvatore-campagna Feb 9, 2024
866c8f4
fix: a few review comments
salvatore-campagna Feb 9, 2024
667972d
fix: a couple more tests
salvatore-campagna Feb 9, 2024
b91b8ca
fix: a few more tests
salvatore-campagna Feb 9, 2024
df3a45a
remove assertion which is version dependent
salvatore-campagna Feb 9, 2024
49a77e9
fix: update skip version
salvatore-campagna Feb 9, 2024
d52e5e4
fix: _ignored field does not have terms vector anymore since it is no…
salvatore-campagna Feb 9, 2024
bc894bb
fix: release response objects
salvatore-campagna Feb 9, 2024
e5a0743
fix: do not rely on order which is lost with doc values
salvatore-campagna Feb 9, 2024
fb8263c
fix: try to release again everything
salvatore-campagna Feb 9, 2024
664958d
test: restore test checking term vectors for the _ignored field
salvatore-campagna Feb 12, 2024
77f2e3b
fix: remove loading on meta fields from StoredFieldsPhase
salvatore-campagna Feb 12, 2024
1bae37a
fix: remove FetchIgnoredMetadataPhase and use FetchFieldsFetcher for …
salvatore-campagna Feb 12, 2024
171c7ad
fix: remove FetchIgnoredMetadataPhase
salvatore-campagna Feb 13, 2024
8bcfe85
fix: do not include unmapped fields
salvatore-campagna Feb 13, 2024
4096422
fix: FetchFieldsPhase always executed to fetch metadata fields
salvatore-campagna Feb 14, 2024
189f6ee
fix: evoid creation of empty list
salvatore-campagna Feb 14, 2024
2f62882
fix: move metadata fields to MetadataFetcher
salvatore-campagna Feb 14, 2024
5b2207c
fix: remove unused class
salvatore-campagna Feb 14, 2024
eca3e1b
fix: do not lead stored fields if not required
salvatore-campagna Feb 14, 2024
300c342
fix: test terms aggregation on _ignored field
salvatore-campagna Feb 14, 2024
9b33013
fix: forgot to make the field not stored
salvatore-campagna Feb 14, 2024
43a5d61
fix: prevent NPE when storedFieldsContext is null
salvatore-campagna Feb 15, 2024
238473e
test: include a few more aggregation tests
salvatore-campagna Feb 15, 2024
0344e28
fix: remove existsQuery from legacy ignored field type
salvatore-campagna Feb 15, 2024
4a233df
refactor: use ValueFetcher in innerGetFetch
salvatore-campagna Feb 19, 2024
f904250
Revert "refactor: use ValueFetcher in innerGetFetch"
salvatore-campagna Feb 20, 2024
05f7553
fix: ignore term vectors generation for the _ignored field
salvatore-campagna Feb 20, 2024
6f9f878
docs: update version
salvatore-campagna Mar 4, 2024
bc6aa30
fix: return _size only if required
salvatore-campagna Mar 4, 2024
c725fb1
test: update skip version
salvatore-campagna Mar 4, 2024
bf9629d
Merge branch 'main' into ignore_field_aggs
salvatore-campagna Mar 4, 2024
bcf16a3
fix: include a mixed cluster test
salvatore-campagna Mar 4, 2024
e31df96
fix: increase health check timeout
salvatore-campagna Mar 5, 2024
05fefdf
fix: expect two documents to be indexed
salvatore-campagna Mar 5, 2024
bbdc263
fix: yaml test skip version and additional phase
salvatore-campagna Mar 5, 2024
bfe6913
fix: phase name in yaml test
salvatore-campagna Mar 5, 2024
509abe5
fix: include logic to deal with backward compatibility
salvatore-campagna Mar 6, 2024
763fc27
refactor: mixed cluster test with exists and aggregation
salvatore-campagna Mar 6, 2024
390fc6b
comment: move it to the right if branch
salvatore-campagna Mar 6, 2024
be24d84
fix: null pointer exception
salvatore-campagna Mar 6, 2024
1c620ea
fix: icnlude index settings and created version in mock
salvatore-campagna Mar 6, 2024
e402020
fix: icnlude index settings and created version in mock
salvatore-campagna Mar 6, 2024
a9bd6cd
fix: 8.14 bwc test
salvatore-campagna Mar 7, 2024
1a34860
fix: incorrect index usage
salvatore-campagna Mar 7, 2024
52c326a
fix: mixed cluster test check on old index version
salvatore-campagna Mar 7, 2024
de91ea6
fix: restore value of DUMP_OUTPUT_ON_FAILURE_PROP_NAME
salvatore-campagna Mar 7, 2024
4a3b4c2
fix: ESSingleNodeTestCase instead of ESIntegTestCase
salvatore-campagna Mar 7, 2024
05a8c5f
fix: move test from IgnoreFieldIT to IgnoredFieldTypeTests
salvatore-campagna Mar 7, 2024
4657791
test: ignore field type selection logic
salvatore-campagna Mar 7, 2024
656534a
fix: use correct type depending on version
salvatore-campagna Mar 7, 2024
e1abe80
fix null pointer exception
salvatore-campagna Mar 7, 2024
773b0a6
fix: use parent exists query implementation
salvatore-campagna Mar 7, 2024
72f6465
fix: remove incorrect null check
salvatore-campagna Mar 7, 2024
d1c0cbe
fix: read _ignored field from stored field for indices created before…
salvatore-campagna Mar 7, 2024
154682b
fix: simplify bwc compatibility
salvatore-campagna Mar 8, 2024
92c06ff
fix: exists query and metadata stored field condition
salvatore-campagna Mar 8, 2024
c30c246
fix: do not skip metadata fields
salvatore-campagna Mar 8, 2024
1f86317
nit: avoid using a temporary variable
salvatore-campagna Mar 8, 2024
1c80140
fix: exclude meta fields when stored_fields = none
salvatore-campagna Mar 11, 2024
85e1ba7
fix: exclude metadata fields handled by MetadataFetcher
salvatore-campagna Mar 11, 2024
570fe56
fix: undo fetch of stored fields
salvatore-campagna Mar 11, 2024
8acc8b1
test: _ignored field upgrade test
salvatore-campagna Mar 12, 2024
55e3d4d
fix: include the _ignored stored field for old indices
salvatore-campagna Mar 12, 2024
c01f2dd
Merge branch 'main' into ignore_field_aggs
salvatore-campagna Mar 12, 2024
ee51ec8
fix: address review comments
salvatore-campagna Mar 12, 2024
7444215
refactor: metadata fields fetching logic and test
salvatore-campagna Mar 13, 2024
bcc1adf
fix: IgnoredFieldMixedClusterUpgradeIT
salvatore-campagna Mar 13, 2024
17996be
Merge branch 'main' into ignore_field_aggs
salvatore-campagna Apr 15, 2024
c2232c9
fix: restore original after merging #106325
salvatore-campagna Apr 15, 2024
98d3856
fix: restore original test outcome
salvatore-campagna Apr 15, 2024
e27bf2e
fix: makre sure we get both old and new documents including _ignored …
salvatore-campagna Apr 15, 2024
9846d32
fix: execute rolling upgrade test only if _ignored is stored in old v…
salvatore-campagna Apr 15, 2024
cee180a
fix: update skip version as of removing stored field for _ignored
salvatore-campagna Apr 15, 2024
eee62f1
fix: skip version and get _ignored
salvatore-campagna Apr 16, 2024
cfc94a2
fix: review comments
salvatore-campagna Apr 18, 2024
c6f4164
fix: update rolling upgrade tests
salvatore-campagna Apr 22, 2024
dc3ce8e
fix: update skip version after switching to 8.15
salvatore-campagna Apr 22, 2024
9c56f59
fix: undo dec ref changes
salvatore-campagna Apr 22, 2024
52f1ef3
fix: review comments
salvatore-campagna Apr 22, 2024
4609a42
Merge branch 'main' into ignore_field_aggs
salvatore-campagna Apr 22, 2024
80a7426
fix: use public version string
salvatore-campagna Apr 22, 2024
ea20632
fix: remove test for term vectors
salvatore-campagna Apr 22, 2024
2ac32f4
docs: update version
salvatore-campagna Apr 22, 2024
3ce075f
fix: update version in reason
salvatore-campagna Apr 22, 2024
f669f9e
fix: remove tests included in another class
salvatore-campagna Apr 22, 2024
58bb648
fix: error message and _ignored debug stored field
salvatore-campagna Apr 22, 2024
08dd66f
fix: remove _ignored
salvatore-campagna Apr 22, 2024
b561aab
fix: remove SuppressWarnings
salvatore-campagna Apr 22, 2024
98a4c6b
fix: remove _ignored
salvatore-campagna Apr 22, 2024
897eca0
fix: error message in bwc test
salvatore-campagna Apr 22, 2024
241a8ca
fix: fetch _ignored field from doc values
salvatore-campagna Apr 23, 2024
cf06f0c
fix: undo unecessary change
salvatore-campagna Apr 23, 2024
4f1816d
fix: non-null ingored fields after implementing fetch from doc values
salvatore-campagna Apr 23, 2024
3276a82
Merge branch 'main' into ignore_field_aggs
salvatore-campagna Apr 23, 2024
6825ada
Revert "fix: remove test for term vectors"
salvatore-campagna Apr 23, 2024
fe0d874
fix: load _ignored from stored field or from doc values
salvatore-campagna Apr 23, 2024
de02373
fix: re-enable terms vector test
salvatore-campagna Apr 24, 2024
1175322
Merge branch 'main' into ignore_field_aggs
salvatore-campagna Apr 24, 2024
e37e1b9
fix: update skip version
salvatore-campagna Apr 29, 2024
bfec2b3
Merge branch 'main' into ignore_field_aggs
salvatore-campagna Apr 29, 2024
4f95463
Merge branch 'main' into ignore_field_aggs
salvatore-campagna Apr 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public void apply(Project project) {
nonInputSystemProperties.systemProperty(TESTS_MAX_PARALLEL_FORKS_SYSPROP, () -> String.valueOf(task.getMaxParallelForks()));

// Disable test failure reporting since this stuff is now captured in build scans
task.getExtensions().getExtraProperties().set(ElasticsearchTestBasePlugin.DUMP_OUTPUT_ON_FAILURE_PROP_NAME, false);
task.getExtensions().getExtraProperties().set(ElasticsearchTestBasePlugin.DUMP_OUTPUT_ON_FAILURE_PROP_NAME, true);

// Disable the security manager and syscall filter since the test framework needs to fork processes
task.systemProperty("tests.security.manager", "false");
Expand Down
6 changes: 6 additions & 0 deletions docs/changelog/101373.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 101373
summary: Adding aggregations support for the `_ignored` field
area: Search
type: feature
issues:
- 59946
17 changes: 17 additions & 0 deletions docs/reference/mapping/fields/ignored-field.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,20 @@ GET _search
}
}
--------------------------------------------------

Since 8.12.0, the `_ignored` field supports aggregations as well.
Copy link
Member

Choose a reason for hiding this comment

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

The version will need updating

For example, the below query finds all fields that got ignored:

[source,console]
--------------------------------------------------
GET _search
{
"aggs": {
"ignored_fields": {
"terms": {
"field": "_ignored"
}
}
}
}
--------------------------------------------------
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ public void testIgnoreAbove() throws IOException {
fields = doc.rootDoc().getFields("field");
assertThat(fields, empty());
fields = doc.rootDoc().getFields("_ignored");
assertEquals(1, fields.size());
assertEquals("field", fields.get(0).stringValue());
assertEquals(2, fields.size());
assertTrue(fields.stream().anyMatch(field -> "field".equals(field.stringValue())));
}

public void testUpdateIgnoreAbove() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ fetch fields:
- gt: { profile.shards.0.fetch.breakdown.load_stored_fields_count: 0 }
- gt: { profile.shards.0.fetch.breakdown.load_stored_fields: 0 }
- match: { profile.shards.0.fetch.debug.stored_fields: [_id, _routing, _source] }
- length: { profile.shards.0.fetch.children: 2 }
- length: { profile.shards.0.fetch.children: 3 }
- match: { profile.shards.0.fetch.children.1.type: FetchIgnoredMetadataPhase }
- match: { profile.shards.0.fetch.children.0.type: FetchFieldsPhase }
- match: { profile.shards.0.fetch.children.1.type: StoredFieldsPhase }
- match: { profile.shards.0.fetch.children.2.type: StoredFieldsPhase }
- gt: { profile.shards.0.fetch.children.0.breakdown.next_reader_count: 0 }
- gt: { profile.shards.0.fetch.children.0.breakdown.next_reader: 0 }
- gt: { profile.shards.0.fetch.children.0.breakdown.next_reader_count: 0 }
Expand All @@ -71,14 +72,15 @@ fetch source:
- gt: { profile.shards.0.fetch.breakdown.load_stored_fields_count: 0 }
- gt: { profile.shards.0.fetch.breakdown.load_stored_fields: 0 }
- match: { profile.shards.0.fetch.debug.stored_fields: [_id, _routing, _source] }
- length: { profile.shards.0.fetch.children: 2 }
- match: { profile.shards.0.fetch.children.0.type: FetchSourcePhase }
- gt: { profile.shards.0.fetch.children.0.breakdown.next_reader_count: 0 }
- gt: { profile.shards.0.fetch.children.0.breakdown.next_reader: 0 }
- gt: { profile.shards.0.fetch.children.0.breakdown.next_reader_count: 0 }
- gt: { profile.shards.0.fetch.children.0.breakdown.next_reader: 0 }
- match: { profile.shards.0.fetch.children.0.debug.fast_path: 1 }
- match: { profile.shards.0.fetch.children.1.type: StoredFieldsPhase }
- length: { profile.shards.0.fetch.children: 3 }
- match: { profile.shards.0.fetch.children.1.type: FetchSourcePhase }
- gt: { profile.shards.0.fetch.children.1.breakdown.next_reader_count: 0 }
- gt: { profile.shards.0.fetch.children.1.breakdown.next_reader: 0 }
- gt: { profile.shards.0.fetch.children.1.breakdown.next_reader_count: 0 }
- gt: { profile.shards.0.fetch.children.1.breakdown.next_reader: 0 }
- match: { profile.shards.0.fetch.children.1.debug.fast_path: 1 }
- match: { profile.shards.0.fetch.children.2.type: StoredFieldsPhase }
- match: { profile.shards.0.fetch.children.0.type: FetchIgnoredMetadataPhase }

---
fetch nested source:
Expand Down Expand Up @@ -135,18 +137,23 @@ fetch nested source:
- gt: { profile.shards.0.fetch.breakdown.load_stored_fields_count: 0 }
- gt: { profile.shards.0.fetch.breakdown.load_stored_fields: 0 }
- match: { profile.shards.0.fetch.debug.stored_fields: [_id, _routing, _source] }
Copy link
Member

Choose a reason for hiding this comment

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

Similar to above, I wonder if we need to update the skip above, that's what I would expect.

Copy link
Member

Choose a reason for hiding this comment

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

I think I forgot about this commit that already made that change: 19db490

- length: { profile.shards.0.fetch.children: 3 }
- match: { profile.shards.0.fetch.children.0.type: FetchSourcePhase }
- length: { profile.shards.0.fetch.children: 4 }
- match: { profile.shards.0.fetch.children.0.type: FetchIgnoredMetadataPhase }
- gt: { profile.shards.0.fetch.children.0.breakdown.next_reader_count: 0 }
- gt: { profile.shards.0.fetch.children.0.breakdown.next_reader: 0 }
- gt: { profile.shards.0.fetch.children.0.breakdown.next_reader_count: 0 }
- gt: { profile.shards.0.fetch.children.0.breakdown.next_reader: 0 }
- match: { profile.shards.0.fetch.children.1.type: InnerHitsPhase }
- match: { profile.shards.0.fetch.children.1.type: FetchSourcePhase }
- gt: { profile.shards.0.fetch.children.1.breakdown.next_reader_count: 0 }
- gt: { profile.shards.0.fetch.children.1.breakdown.next_reader: 0 }
- gt: { profile.shards.0.fetch.children.1.breakdown.next_reader_count: 0 }
- gt: { profile.shards.0.fetch.children.1.breakdown.next_reader: 0 }
- match: { profile.shards.0.fetch.children.2.type: StoredFieldsPhase }
- match: { profile.shards.0.fetch.children.2.type: InnerHitsPhase }
- gt: { profile.shards.0.fetch.children.2.breakdown.next_reader_count: 0 }
- gt: { profile.shards.0.fetch.children.2.breakdown.next_reader: 0 }
- gt: { profile.shards.0.fetch.children.2.breakdown.next_reader_count: 0 }
- gt: { profile.shards.0.fetch.children.2.breakdown.next_reader: 0 }
- match: { profile.shards.0.fetch.children.3.type: StoredFieldsPhase }

---
disabling stored fields removes fetch sub phases:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/*
* 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.index.mapper;

import org.elasticsearch.action.DocWriteResponse;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.document.DocumentField;
import org.elasticsearch.index.query.ExistsQueryBuilder;
import org.elasticsearch.index.query.IdsQueryBuilder;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.aggregations.bucket.terms.StringTerms;
import org.elasticsearch.search.aggregations.metrics.InternalAvg;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentFactory;
import org.junit.Before;

import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE;
import static org.elasticsearch.search.aggregations.AggregationBuilders.avg;
import static org.elasticsearch.search.aggregations.AggregationBuilders.terms;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.hamcrest.Matchers.hasSize;

@SuppressWarnings("resource")
public class IgnoreFieldIT extends ESIntegTestCase {
Copy link
Member

Choose a reason for hiding this comment

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

does this need to be an integ test case? Could it be a single node test case instead? Even better, there are probably parts that could become unit test and not need to spin up a cluster with multiple nodes? Can you check the existing coverage for _ignored in the existing yaml tests? Shall we add a basic yaml test that aggregates on it? We also need to add a bw compatibility test that verifies the behaviour against a mixed cluster.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I need to add a few tests where I run at least a handful of aggregations on it...if I try to imagine possible use case scenarios I imagine top[Hits/Metrics] aggs maybe nested in daily/weekly/monthly histograms...date range, histogram and cardinality at least.


public static final String NUMERIC_FIELD_NAME = "numeric_field";
public static final String DATE_FIELD_NAME = "date_field";
public static final String TEST_INDEX = "test-index";
public static final String CORRECT_FIELD_TYPE_DOC_ID = "1";
public static final String WRONG_FIELD_TYPE_DOC_ID = "2";

@Before
public void createTestIndex() throws Exception {
XContentBuilder mapping = XContentFactory.jsonBuilder()
.startObject()
.startObject("_doc")
.startObject("properties")
.startObject(NUMERIC_FIELD_NAME)
.field("type", "long")
.field("ignore_malformed", true)
.endObject()
.startObject(DATE_FIELD_NAME)
.field("type", "date")
.field("ignore_malformed", true)
.endObject()
.endObject()
.endObject()
.endObject();
assertAcked(indicesAdmin().prepareCreate(TEST_INDEX).setMapping(mapping));
indexTestDoc(NUMERIC_FIELD_NAME, CORRECT_FIELD_TYPE_DOC_ID, "42");
indexTestDoc(NUMERIC_FIELD_NAME, WRONG_FIELD_TYPE_DOC_ID, "forty-two");
}

public void testIgnoreFieldFetch() {
SearchResponse searchResponse = prepareSearch().setQuery(new IdsQueryBuilder().addIds(CORRECT_FIELD_TYPE_DOC_ID))
.addFetchField(NUMERIC_FIELD_NAME)
.get();
assertHitCount(searchResponse, 1);
SearchHit hit = searchResponse.getHits().getAt(0);
DocumentField numericField = hit.field(NUMERIC_FIELD_NAME);
assertNotNull(numericField);
assertEquals(42, (long) numericField.getValue());
DocumentField ignoredField = hit.field(IgnoredFieldMapper.NAME);
assertNull(ignoredField);

searchResponse = prepareSearch().setQuery(new IdsQueryBuilder().addIds(WRONG_FIELD_TYPE_DOC_ID))
.addFetchField(NUMERIC_FIELD_NAME)
.get();
assertHitCount(searchResponse, 1);
hit = searchResponse.getHits().getAt(0);
numericField = hit.field(NUMERIC_FIELD_NAME);
assertNotNull(numericField);
assertEquals("forty-two", numericField.getIgnoredValues().get(0));
ignoredField = hit.field(IgnoredFieldMapper.NAME);
assertNotNull(ignoredField);
assertEquals(NUMERIC_FIELD_NAME, ignoredField.getValue());
}

public void testExistsQuery() {
Copy link
Member

Choose a reason for hiding this comment

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

This should probably be added as a unit test to IgnoredFieldTypeTests? Same probably for the other two tests you have? Can we also have a unit test that verifies the versioning logic?

SearchResponse searchResponse = null;
try {
searchResponse = prepareSearch().setQuery(new ExistsQueryBuilder(IgnoredFieldMapper.NAME))
.addFetchField(NUMERIC_FIELD_NAME)
.get();
assertHitCount(searchResponse, 1);
SearchHit hit = searchResponse.getHits().getAt(0);
assertEquals(WRONG_FIELD_TYPE_DOC_ID, hit.getId());
} finally {
if (searchResponse != null) {
searchResponse.decRef();
}
}
}

public void testIgnoreFieldAggregation() {
Copy link
Member

Choose a reason for hiding this comment

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

did you mean testIgnoredFieldAggregation? Could you use the correct field name in the other test methods too?

SearchResponse avgSearch = null;
try {
indexTestDoc(NUMERIC_FIELD_NAME, "correct-44", "44");
avgSearch = prepareSearch(TEST_INDEX).setSize(0).addAggregation(avg("numeric-field-aggs").field(NUMERIC_FIELD_NAME)).get();
assertTrue(avgSearch.hasAggregations());
InternalAvg avg = avgSearch.getAggregations().get("numeric-field-aggs");
assertNotNull(avg);
assertEquals(43.0, avg.getValue(), 0.0);

indexTestDoc(NUMERIC_FIELD_NAME, "wrong-44", "forty-four");
indexTestDoc(DATE_FIELD_NAME, "wrong-date", "today");
SearchResponse termsSearch = prepareSearch(TEST_INDEX).setSize(0)
.addAggregation(terms("ignored-field-aggs").field(IgnoredFieldMapper.NAME))
.get();
assertTrue(termsSearch.hasAggregations());
StringTerms terms = termsSearch.getAggregations().get("ignored-field-aggs");
assertNotNull(terms);
assertThat(terms.getBuckets(), hasSize(2));
StringTerms.Bucket numericFieldBucket = terms.getBucketByKey(NUMERIC_FIELD_NAME);
assertEquals(NUMERIC_FIELD_NAME, numericFieldBucket.getKeyAsString());
assertEquals(2, numericFieldBucket.getDocCount());
StringTerms.Bucket dateFieldBucket = terms.getBucketByKey(DATE_FIELD_NAME);
assertEquals(DATE_FIELD_NAME, dateFieldBucket.getKeyAsString());
assertEquals(1, dateFieldBucket.getDocCount());
} finally {
if (avgSearch != null) {
avgSearch.decRef();
}
}
}

private static void indexTestDoc(String testField, String docId, String testValue) {
DocWriteResponse docWriteResponse = client().prepareIndex(TEST_INDEX)
.setId(docId)
.setSource(testField, testValue)
.setRefreshPolicy(IMMEDIATE)
.get();
assertEquals(RestStatus.CREATED, docWriteResponse.status());
}
}
Loading