use of org.elasticsearch.search.SearchHitField in project elasticsearch by elastic.
the class OldIndexBackwardsCompatibilityIT method assertStoredBinaryFields.
/**
* Make sure we can load stored binary fields.
*/
void assertStoredBinaryFields(String indexName, Version version) throws Exception {
SearchRequestBuilder builder = client().prepareSearch(indexName);
builder.setQuery(QueryBuilders.matchAllQuery());
builder.setSize(100);
builder.addStoredField("binary");
SearchHits hits = builder.get().getHits();
assertEquals(100, hits.getHits().length);
for (SearchHit hit : hits) {
SearchHitField field = hit.field("binary");
assertNotNull(field);
Object value = field.getValue();
assertTrue(value instanceof BytesArray);
assertEquals(16, ((BytesArray) value).length());
}
}
use of org.elasticsearch.search.SearchHitField in project elasticsearch by elastic.
the class SearchFieldsIT method testSingleValueFieldDatatField.
// see #8203
public void testSingleValueFieldDatatField() throws ExecutionException, InterruptedException {
assertAcked(client().admin().indices().prepareCreate("test").addMapping("type", "test_field", "type=keyword").get());
indexRandom(true, client().prepareIndex("test", "type", "1").setSource("test_field", "foobar"));
refresh();
SearchResponse searchResponse = client().prepareSearch("test").setTypes("type").setSource(new SearchSourceBuilder().query(QueryBuilders.matchAllQuery()).fieldDataField("test_field")).get();
assertHitCount(searchResponse, 1);
Map<String, SearchHitField> fields = searchResponse.getHits().getHits()[0].getFields();
assertThat(fields.get("test_field").getValue(), equalTo("foobar"));
}
use of org.elasticsearch.search.SearchHitField in project elasticsearch by elastic.
the class SearchFieldsIT method testLoadMetadata.
public void testLoadMetadata() throws Exception {
assertAcked(prepareCreate("test").addMapping("parent").addMapping("my-type1", "_parent", "type=parent"));
indexRandom(true, client().prepareIndex("test", "my-type1", "1").setRouting("1").setParent("parent_1").setSource(jsonBuilder().startObject().field("field1", "value").endObject()));
SearchResponse response = client().prepareSearch("test").addStoredField("field1").get();
assertSearchResponse(response);
assertHitCount(response, 1);
Map<String, SearchHitField> fields = response.getHits().getAt(0).getFields();
assertThat(fields.get("field1"), nullValue());
assertThat(fields.get("_routing").isMetadataField(), equalTo(true));
assertThat(fields.get("_routing").getValue().toString(), equalTo("1"));
assertThat(fields.get("_parent").isMetadataField(), equalTo(true));
assertThat(fields.get("_parent").getValue().toString(), equalTo("parent_1"));
}
Aggregations