Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -1120,9 +1120,10 @@ public void testLoadMetadata() throws Exception {
assertSearchResponse(response);
assertHitCount(response, 1);

Map<String, DocumentField> fields = response.getHits().getAt(0).getFields();
Map<String, DocumentField> fields = response.getHits().getAt(0).getMetadataFields();

assertThat(fields.get("field1"), nullValue());
assertThat(fields.get("_routing").getValue().toString(), equalTo("1"));
assertThat(response.getHits().getAt(0).getDocumentFields().size(), equalTo(0));
}
}
16 changes: 15 additions & 1 deletion server/src/main/java/org/elasticsearch/search/SearchHit.java
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,23 @@ public void setDocumentField(String fieldName, DocumentField field) {
this.documentFields.put(fieldName, field);
}

/**
* @return a map of metadata fields for this hit
*/
public Map<String, DocumentField> getMetadataFields() {
return Collections.unmodifiableMap(metaFields);
}

/**
* @return a map of non-metadata fields requested for this hit
*/
public Map<String, DocumentField> getDocumentFields() {
return Collections.unmodifiableMap(documentFields);
}

/**
* A map of hit fields (from field name to hit fields) if additional fields
* were required to be loaded.
* were required to be loaded. Includes both document and metadata fields.
*/
public Map<String, DocumentField> getFields() {
if (metaFields.size() > 0 || documentFields.size() > 0) {
Expand Down