use of org.elasticsearch.common.document.DocumentField in project elasticflow by springwings.
the class EsSearcher method addResult.
private void addResult(SearcherResult res, SearchResponse response, SearcherModel<?, ?, ?> fq, List<String> returnFields) {
SearchHits searchHits = response.getHits();
res.setTotalHit(searchHits.getTotalHits().value);
SearchHit[] hits = searchHits.getHits();
for (SearchHit h : hits) {
Map<String, DocumentField> fieldMap = h.getFields();
ResponseDataUnit u = ResponseDataUnit.getInstance();
for (Map.Entry<String, DocumentField> e : fieldMap.entrySet()) {
String name = e.getKey();
EFField param = instanceConfig.getWriteFields().get(name);
DocumentField v = e.getValue();
if (param != null && param.getSeparator() != null) {
u.addObject(name, v.getValues());
} else if (returnFields.contains(name)) {
u.addObject(name, v.getValue());
}
}
if (fq.isShowQueryInfo()) {
u.addObject("_SCORE", h.getExplanation().getValue());
u.addObject("_EXPLAINS", h.getExplanation().toString().replace("", ""));
}
res.getUnitSet().add(u);
}
if (fq.getFacetSearchParams() != null && response.getAggregations() != null) {
res.setFacetInfo(JSON.parseObject(response.toString()).get("aggregations"));
}
}
use of org.elasticsearch.common.document.DocumentField in project spring-data-elasticsearch by spring-projects.
the class DocumentAdaptersUnitTests method shouldAdaptSearchResponse.
// DATAES-628, DATAES-848
@Test
public void shouldAdaptSearchResponse() {
Map<String, DocumentField> fields = Collections.singletonMap("field", new DocumentField("field", Collections.singletonList("value")));
SearchShardTarget shard = new SearchShardTarget("node", new ShardId("index", "uuid", 42), null);
SearchHit searchHit = new SearchHit(123, "my-id", new Text("type"), null, fields);
searchHit.shard(shard);
searchHit.setSeqNo(1);
searchHit.setPrimaryTerm(2);
searchHit.score(42);
SearchDocument document = DocumentAdapters.from(searchHit);
assertThat(document.getIndex()).isEqualTo("index");
assertThat(document.hasId()).isTrue();
assertThat(document.getId()).isEqualTo("my-id");
assertThat(document.hasVersion()).isFalse();
assertThat(document.getScore()).isBetween(42f, 42f);
assertThat(document.get("field")).isEqualTo("value");
assertThat(document.hasSeqNo()).isTrue();
assertThat(document.getSeqNo()).isEqualTo(1);
assertThat(document.hasPrimaryTerm()).isTrue();
assertThat(document.getPrimaryTerm()).isEqualTo(2);
}
use of org.elasticsearch.common.document.DocumentField in project spring-data-elasticsearch by spring-projects.
the class DocumentAdaptersUnitTests method shouldAdaptGetResponse.
// DATAES-628, DATAES-848
@Test
public void shouldAdaptGetResponse() {
Map<String, DocumentField> fields = Collections.singletonMap("field", new DocumentField("field", Collections.singletonList("value")));
GetResult getResult = new GetResult("index", "type", "my-id", 1, 2, 42, true, null, fields, null);
GetResponse response = new GetResponse(getResult);
Document document = DocumentAdapters.from(response);
assertThat(document.getIndex()).isEqualTo("index");
assertThat(document.hasId()).isTrue();
assertThat(document.getId()).isEqualTo("my-id");
assertThat(document.hasVersion()).isTrue();
assertThat(document.getVersion()).isEqualTo(42);
assertThat(document.get("field")).isEqualTo("value");
assertThat(document.hasSeqNo()).isTrue();
assertThat(document.getSeqNo()).isEqualTo(1);
assertThat(document.hasPrimaryTerm()).isTrue();
assertThat(document.getPrimaryTerm()).isEqualTo(2);
}
use of org.elasticsearch.common.document.DocumentField in project spring-data-elasticsearch by spring-projects.
the class DocumentAdaptersUnitTests method shouldAdaptGetResult.
// DATAES-799, DATAES-848
@Test
public void shouldAdaptGetResult() {
Map<String, DocumentField> fields = Collections.singletonMap("field", new DocumentField("field", Collections.singletonList("value")));
GetResult getResult = new GetResult("index", "type", "my-id", 1, 2, 42, true, null, fields, null);
Document document = DocumentAdapters.from(getResult);
assertThat(document.getIndex()).isEqualTo("index");
assertThat(document.hasId()).isTrue();
assertThat(document.getId()).isEqualTo("my-id");
assertThat(document.hasVersion()).isTrue();
assertThat(document.getVersion()).isEqualTo(42);
assertThat(document.get("field")).isEqualTo("value");
assertThat(document.hasSeqNo()).isTrue();
assertThat(document.getSeqNo()).isEqualTo(1);
assertThat(document.hasPrimaryTerm()).isTrue();
assertThat(document.getPrimaryTerm()).isEqualTo(2);
}
use of org.elasticsearch.common.document.DocumentField in project spring-data-elasticsearch by spring-projects.
the class DocumentAdaptersUnitTests method shouldRenderToJson.
// DATAES-628
@Test
public void shouldRenderToJson() {
Map<String, DocumentField> fields = new LinkedHashMap<>();
fields.put("string", new DocumentField("string", Collections.singletonList("value")));
fields.put("bool", new DocumentField("bool", Arrays.asList(true, true, false)));
SearchHit searchHit = new SearchHit(123, "my-id", new Text("type"), fields, null);
SearchDocument document = DocumentAdapters.from(searchHit);
assertThat(document.toJson()).isEqualTo("{\"string\":\"value\",\"bool\":[true,true,false]}");
}
Aggregations