Recently, I am debugging ES 6.3 indexing flow through source code. I found that ES will new two objects for handling keyword type field. One is Field object for revert index store, and another one is SortedNumericDocValueField for handling doc value.
My question is that why ES create two fields? In my opinion, we could just create one Field object, and set FieldType with both indexed and doc value type options. In lucene level, it only just check field's type has these two options then handle them separately.
I also try to modify KeywordFieldMapper.java and this is my pseudocode:
Field field = new Field() FieldType ft = new FieldType(); ft.setDocValueType(SORT_SET); ft.setIndexOptions(IndexOptions.DOCS); ft.setStored(true); ft.setDimensions(2, 16); ... field.setFieldType(ft);
And I saw Lucene could store this field correctly with doc values and revert index. Any one please help me？