|
19 | 19 | package org.elasticsearch.index.mapper;
|
20 | 20 |
|
21 | 21 | import org.apache.lucene.document.LongPoint;
|
| 22 | +import org.apache.lucene.document.NumericDocValuesField; |
22 | 23 | import org.apache.lucene.document.SortedNumericDocValuesField;
|
23 | 24 | import org.apache.lucene.index.DirectoryReader;
|
24 | 25 | import org.apache.lucene.index.IndexOptions;
|
25 | 26 | import org.apache.lucene.index.IndexReader;
|
26 | 27 | import org.apache.lucene.index.IndexWriter;
|
27 | 28 | import org.apache.lucene.index.IndexWriterConfig;
|
28 | 29 | import org.apache.lucene.index.MultiReader;
|
| 30 | +import org.apache.lucene.index.SortedNumericDocValues; |
| 31 | +import org.apache.lucene.search.DocIdSetIterator; |
29 | 32 | import org.apache.lucene.search.IndexOrDocValuesQuery;
|
30 | 33 | import org.apache.lucene.search.Query;
|
31 | 34 | import org.apache.lucene.store.Directory;
|
|
37 | 40 | import org.elasticsearch.common.time.DateMathParser;
|
38 | 41 | import org.elasticsearch.core.internal.io.IOUtils;
|
39 | 42 | import org.elasticsearch.index.IndexSettings;
|
| 43 | +import org.elasticsearch.index.fielddata.AtomicNumericFieldData; |
| 44 | +import org.elasticsearch.index.fielddata.IndexNumericFieldData; |
| 45 | +import org.elasticsearch.index.fielddata.plain.SortedNumericDVIndexFieldData; |
40 | 46 | import org.elasticsearch.index.mapper.DateFieldMapper.DateFieldType;
|
41 | 47 | import org.elasticsearch.index.mapper.MappedFieldType.Relation;
|
42 | 48 | import org.elasticsearch.index.mapper.ParseContext.Document;
|
@@ -214,4 +220,33 @@ public void testRangeQuery() throws IOException {
|
214 | 220 | () -> ft.rangeQuery(date1, date2, true, true, null, null, null, context));
|
215 | 221 | assertEquals("Cannot search on field [field] since it is not indexed.", e.getMessage());
|
216 | 222 | }
|
| 223 | + |
| 224 | + public void testDateNanoDocValues() throws IOException { |
| 225 | + // Create an index with some docValues |
| 226 | + Directory dir = newDirectory(); |
| 227 | + IndexWriter w = new IndexWriter(dir, new IndexWriterConfig(null)); |
| 228 | + Document doc = new Document(); |
| 229 | + NumericDocValuesField docValuesField = new NumericDocValuesField("my_date", 1444608000000L); |
| 230 | + doc.add(docValuesField); |
| 231 | + w.addDocument(doc); |
| 232 | + docValuesField.setLongValue(1459641600000L); |
| 233 | + w.addDocument(doc); |
| 234 | + // Create the doc values reader |
| 235 | + Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) |
| 236 | + .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1).build(); |
| 237 | + IndexSettings indexSettings = new IndexSettings(IndexMetaData.builder("foo").settings(settings).build(), settings); |
| 238 | + SortedNumericDVIndexFieldData fieldData = new SortedNumericDVIndexFieldData(indexSettings.getIndex(), "my_date", |
| 239 | + IndexNumericFieldData.NumericType.DATE_NANOSECONDS); |
| 240 | + // Read index and check the doc values |
| 241 | + DirectoryReader reader = DirectoryReader.open(w); |
| 242 | + assertTrue(reader.leaves().size() > 0); |
| 243 | + AtomicNumericFieldData a = fieldData.load(reader.leaves().get(0).reader().getContext()); |
| 244 | + SortedNumericDocValues docValues = a.getLongValues(); |
| 245 | + assertEquals(0, docValues.nextDoc()); |
| 246 | + assertEquals(1, docValues.nextDoc()); |
| 247 | + assertEquals(DocIdSetIterator.NO_MORE_DOCS, docValues.nextDoc()); |
| 248 | + reader.close(); |
| 249 | + w.close(); |
| 250 | + dir.close(); |
| 251 | + } |
217 | 252 | }
|
0 commit comments