30
30
import org .apache .lucene .search .Scorable ;
31
31
import org .apache .lucene .search .ScoreMode ;
32
32
import org .apache .lucene .store .Directory ;
33
- import org .apache .lucene .util .BytesRef ;
34
33
import org .apache .lucene .util .SetOnce ;
35
34
import org .elasticsearch .action .admin .cluster .health .ClusterHealthResponse ;
36
35
import org .elasticsearch .action .admin .indices .create .CreateIndexRequestBuilder ;
45
44
import org .elasticsearch .cluster .routing .allocation .DiskThresholdSettings ;
46
45
import org .elasticsearch .common .Priority ;
47
46
import org .elasticsearch .common .Strings ;
48
- import org .elasticsearch .common .bytes .BytesArray ;
49
- import org .elasticsearch .common .lucene .BytesRefs ;
47
+ import org .elasticsearch .common .bytes .BytesReference ;
50
48
import org .elasticsearch .common .settings .Settings ;
51
49
import org .elasticsearch .common .unit .TimeValue ;
52
50
import org .elasticsearch .common .util .BigArrays ;
55
53
import org .elasticsearch .common .xcontent .NamedXContentRegistry ;
56
54
import org .elasticsearch .common .xcontent .XContentBuilder ;
57
55
import org .elasticsearch .common .xcontent .XContentParser ;
56
+ import org .elasticsearch .common .xcontent .XContentParser .Token ;
57
+ import org .elasticsearch .common .xcontent .XContentParserUtils ;
58
58
import org .elasticsearch .common .xcontent .XContentType ;
59
59
import org .elasticsearch .common .xcontent .json .JsonXContent ;
60
60
import org .elasticsearch .core .internal .io .IOUtils ;
@@ -444,36 +444,40 @@ public void collect(int doc) throws IOException {
444
444
/**
445
445
* Use a {@linkplain FieldMapper} to extract values from doc values.
446
446
*/
447
- protected static List <?> fetchFromDocValues (FieldMapper mapper , String format , Object sourceValue ) throws IOException {
447
+ protected static List <?> fetchFromDocValues (FieldMapper mapper , DocValueFormat format , Object sourceValue ) throws IOException {
448
448
MapperService mapperService = mock (MapperService .class );
449
449
when (mapperService .fieldType (any ())).thenReturn (mapper .fieldType ());
450
450
Function <MappedFieldType , IndexFieldData <?>> fieldDataLookup = mft -> mft .fielddataBuilder ("test" , () -> {
451
451
throw new UnsupportedOperationException ();
452
452
}).build (new IndexFieldDataCache .None (), new NoneCircuitBreakerService (), mapperService );
453
453
try (Directory directory = newDirectory (); RandomIndexWriter iw = new RandomIndexWriter (random (), directory )) {
454
- BytesRef source = BytesRefs . toBytesRef (
454
+ BytesReference source = BytesReference . bytes (
455
455
JsonXContent .contentBuilder ().startObject ().field (mapper .name (), sourceValue ).endObject ()
456
456
);
457
- ParseContext .Document doc = new ParseContext .Document ();
458
- ParseContext context = mock (ParseContext .class );
459
- when (context .doc ()).thenReturn (doc );
460
- when (context .sourceToParse ()).thenReturn (new SourceToParse ("test" , "id" , new BytesArray (source ), XContentType .JSON ));
461
457
try (
462
458
XContentParser parser = JsonXContent .jsonXContent .createParser (
463
459
NamedXContentRegistry .EMPTY ,
464
460
DeprecationHandler .THROW_UNSUPPORTED_OPERATION ,
465
- source .utf8ToString ()
461
+ source .streamInput ()
466
462
)
467
463
) {
464
+ ParseContext .Document doc = new ParseContext .Document ();
465
+ ParseContext context = mock (ParseContext .class );
466
+ when (context .doc ()).thenReturn (doc );
467
+ when (context .sourceToParse ()).thenReturn (new SourceToParse ("test" , "id" , source , XContentType .JSON ));
468
+ when (context .parser ()).thenReturn (parser );
468
469
parser .nextToken ();
470
+ XContentParserUtils .ensureExpectedToken (Token .START_OBJECT , parser .currentToken (), parser ::getTokenLocation );
471
+ XContentParserUtils .ensureFieldName (parser , parser .nextToken (), mapper .name ());
469
472
parser .nextToken ();
470
473
mapper .parse (context );
474
+ parser .nextToken ();
475
+ XContentParserUtils .ensureExpectedToken (Token .END_OBJECT , parser .currentToken (), parser ::getTokenLocation );
476
+ iw .addDocument (doc );
471
477
}
472
- iw .addDocument (doc );
473
478
try (DirectoryReader reader = iw .getReader ()) {
474
479
IndexSearcher indexSearcher = newSearcher (reader );
475
480
SearchLookup lookup = new SearchLookup (mapperService , fieldDataLookup );
476
- DocValueFormat dvFormat = mapper .fieldType ().docValueFormat (format , null );
477
481
IndexFieldData <?> ifd = lookup .doc ().getForField (mapper .fieldType ());
478
482
SetOnce <List <?>> result = new SetOnce <>();
479
483
indexSearcher .search (new MatchAllDocsQuery (), new Collector () {
@@ -484,7 +488,7 @@ public ScoreMode scoreMode() {
484
488
485
489
@ Override
486
490
public LeafCollector getLeafCollector (LeafReaderContext context ) throws IOException {
487
- LeafValueFetcher lvf = ifd .load (context ).buildFetcher (dvFormat );
491
+ LeafValueFetcher lvf = ifd .load (context ).buildFetcher (format );
488
492
return new LeafCollector () {
489
493
@ Override
490
494
public void setScorer (Scorable scorer ) throws IOException {}
0 commit comments