Skip to content

Commit

Permalink
Address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmitterdorfer committed Dec 22, 2023
1 parent 55f4554 commit 47732ce
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

package org.elasticsearch.xpack.countedkeyword;

import org.apache.lucene.index.DocValuesType;
import org.apache.lucene.index.IndexOptions;
import org.apache.lucene.index.IndexableField;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MappedFieldType;
Expand Down Expand Up @@ -82,4 +84,15 @@ public void testDottedFieldNames() throws IOException {
List<IndexableField> fields = doc.rootDoc().getFields("dotted.field");
assertEquals(1, fields.size());
}

public void testDisableIndex() throws IOException {
DocumentMapper mapper = createDocumentMapper(
fieldMapping(b -> b.field("type", CountedKeywordFieldMapper.CONTENT_TYPE).field("index", false))
);
ParsedDocument doc = mapper.parse(source(b -> b.field("field", "1234")));
List<IndexableField> fields = doc.rootDoc().getFields("field");
assertEquals(1, fields.size());
assertEquals(IndexOptions.NONE, fields.get(0).fieldType().indexOptions());
assertEquals(DocValuesType.SORTED_SET, fields.get(0).fieldType().docValuesType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,6 @@ setup:
type: counted_keyword


- do:
indices.create:
index: test-events-no-index
body:
mappings:
properties:
events:
type: counted_keyword
index: false


- do:
index:
index: test-events
Expand All @@ -38,17 +27,21 @@ setup:
body: { "events": [ "a", "b", "b", "b", "c" ] }

- do:
index:
index: test-events-no-index
id: "1"
body: { "events": [ "a", "a", "b" ] }

indices.refresh: { }

---
"Counted keyword is searchable by default":
- do:
indices.refresh: { }
field_caps:
index: test-events
fields: [ events ]

- match: { fields.events.counted_keyword.searchable: true }
- match: { fields.events.counted_keyword.aggregatable: true }

---
"Counted Terms agg":

- do:
search:
index: test-events
Expand All @@ -66,20 +59,3 @@ setup:
- match: { aggregations.event_terms.buckets.2.key: "c" }
- match: { aggregations.event_terms.buckets.2.doc_count: 2 }
- length: { aggregations.event_terms.buckets: 3 }

# although the field is not indexed, the counted_terms agg should still work
- do:
search:
index: test-events-no-index
body:
size: 0
aggs:
event_terms:
counted_terms:
field: events

- match: { aggregations.event_terms.buckets.0.key: "a" }
- match: { aggregations.event_terms.buckets.0.doc_count: 2 }
- match: { aggregations.event_terms.buckets.1.key: "b" }
- match: { aggregations.event_terms.buckets.1.doc_count: 1 }
- length: { aggregations.event_terms.buckets: 2 }
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
setup:

- skip:
version: " - 8.12.99"
reason: "index option on counted_keyword was added in 8.13"

- do:
indices.create:
index: test-events-no-index
body:
mappings:
properties:
events:
type: counted_keyword
index: false

- do:
index:
index: test-events-no-index
id: "1"
body: { "events": [ "a", "a", "b" ] }


- do:
indices.refresh: { }

---
"Counted keyword with index false is not searchable":
- do:
field_caps:
index: test-events-no-index
fields: [ events ]

- match: { fields.events.counted_keyword.searchable: false }
- match: { fields.events.counted_keyword.aggregatable: true }

---
"Counted Terms agg only relies on doc values":
# although the field is not indexed, the counted_terms agg should still work
- do:
search:
index: test-events-no-index
body:
size: 0
aggs:
event_terms:
counted_terms:
field: events

- match: { aggregations.event_terms.buckets.0.key: "a" }
- match: { aggregations.event_terms.buckets.0.doc_count: 2 }
- match: { aggregations.event_terms.buckets.1.key: "b" }
- match: { aggregations.event_terms.buckets.1.doc_count: 1 }
- length: { aggregations.event_terms.buckets: 2 }

0 comments on commit 47732ce

Please sign in to comment.