本文整理汇总了Java中org.elasticsearch.search.SearchHit.getSourceAsMap方法的典型用法代码示例。如果您正苦于以下问题:Java SearchHit.getSourceAsMap方法的具体用法?Java SearchHit.getSourceAsMap怎么用?Java SearchHit.getSourceAsMap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.search.SearchHit
的用法示例。
在下文中一共展示了SearchHit.getSourceAsMap方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTopFilmes
import org.elasticsearch.search.SearchHit; //导入方法依赖的package包/类
public List<Map<String, Object>> getTopFilmes() {
List<Map<String, Object>> filmes = new ArrayList<Map<String, Object>>();
// Seu código deve vir daqui para baixo
FieldSortBuilder sort = new FieldSortBuilder("vote_average").order(SortOrder.DESC);
SearchResponse response = client.prepareSearch(INDEX).setTypes(TYPE).addSort(sort).execute().actionGet();
SearchHit[] results = response.getHits().getHits();
for (SearchHit hit : results) {
System.out.println("------------------------------");
Map<String, Object> result = hit.getSourceAsMap();
filmes.add(result);
System.out.println(result);
}
return filmes;
}
示例2: queryToList
import org.elasticsearch.search.SearchHit; //导入方法依赖的package包/类
/**
*
* @param data
* @param queryBuilder
* @param postFilter
*/
@SuppressWarnings("rawtypes")
private void queryToList(UAVHttpMessage data, QueryBuilder queryBuilder, QueryBuilder postFilter,
SortBuilder[] sorts) {
SearchResponse sr = query(data, queryBuilder, postFilter, sorts);
SearchHits shits = sr.getHits();
List<Map<String, Object>> records = new ArrayList<Map<String, Object>>();
for (SearchHit sh : shits) {
Map<String, Object> record = sh.getSourceAsMap();
if (record == null) {
continue;
}
records.add(record);
}
data.putResponse("rs", JSONHelper.toString(records));
// 返回总的条数
data.putResponse("count", shits.getTotalHits() + "");
}
示例3: getRecords
import org.elasticsearch.search.SearchHit; //导入方法依赖的package包/类
private List<Map<String, Object>> getRecords(SearchResponse sr) {
SearchHits shits = sr.getHits();
List<Map<String, Object>> records = new ArrayList<Map<String, Object>>();
for (SearchHit sh : shits) {
Map<String, Object> record = sh.getSourceAsMap();
if (record == null) {
continue;
}
records.add(record);
}
return records;
}
示例4: queryWithConstraints
import org.elasticsearch.search.SearchHit; //导入方法依赖的package包/类
public List<Map<String, Object>> queryWithConstraints(final String indexName, final String fieldName, final String fieldValue, final Map<String, String> constraints, boolean latest) throws IOException {
SearchRequestBuilder request = this.elasticsearchClient.prepareSearch(indexName)
.setSearchType(SearchType.QUERY_THEN_FETCH)
.setFrom(0);
BoolQueryBuilder bFilter = QueryBuilders.boolQuery();
bFilter.filter(QueryBuilders.constantScoreQuery(QueryBuilders.constantScoreQuery(QueryBuilders.termQuery(fieldName, fieldValue))));
for (Object o : constraints.entrySet()) {
@SuppressWarnings("rawtypes")
Map.Entry entry = (Map.Entry) o;
bFilter.filter(QueryBuilders.constantScoreQuery(QueryBuilders.termQuery((String) entry.getKey(), ((String) entry.getValue()).toLowerCase())));
}
request.setQuery(bFilter);
// get response
SearchResponse response = request.execute().actionGet();
// evaluate search result
ArrayList<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
SearchHit[] hits = response.getHits().getHits();
for (SearchHit hit: hits) {
Map<String, Object> map = hit.getSourceAsMap();
result.add(map);
}
return result;
}
示例5: extractData
import org.elasticsearch.search.SearchHit; //导入方法依赖的package包/类
/**
* @param response
* @return
*/
@SuppressWarnings("unchecked")
public List<Map> extractData(SearchResponse response) {
List<Map> data = new LinkedList<>();
SearchHits hits = response.getHits();
try {
for (SearchHit hit : hits) {
Map<String, Object> sourceMap = hit.getSourceAsMap();
data.add(sourceMap);
}
} catch (Exception e) {
}
return data;
}
示例6: queryToList
import org.elasticsearch.search.SearchHit; //导入方法依赖的package包/类
/**
*
* @param data
* @param queryBuilder
* @param postFilter
*/
@SuppressWarnings("rawtypes")
private void queryToList(UAVHttpMessage data, QueryBuilder queryBuilder, QueryBuilder postFilter,
SortBuilder[] sorts) {
SearchResponse sr = query(data, queryBuilder, postFilter, sorts);
if (sr == null) {
return;
}
SearchHits shits = sr.getHits();
List<Map<String, Object>> records = new ArrayList<Map<String, Object>>();
for (SearchHit sh : shits) {
Map<String, Object> record = sh.getSourceAsMap();
if (record == null) {
continue;
}
records.add(record);
}
data.putResponse("rs", JSONHelper.toString(records));
// 返回总的条数
data.putResponse("count", shits.getTotalHits() + "");
}
示例7: queryToList
import org.elasticsearch.search.SearchHit; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
private void queryToList(UAVHttpMessage data, QueryBuilder queryBuilder, QueryBuilder postFilter,
SortBuilder[] sorts) {
SearchResponse sr = query(data, queryBuilder, postFilter, sorts);
SearchHits shits = sr.getHits();
List<Map<String, Object>> records = new ArrayList<Map<String, Object>>();
for (SearchHit sh : shits) {
Map<String, Object> record = sh.getSourceAsMap();
if (record == null) {
continue;
}
records.add(record);
}
// 如果只存在eline则需要把结果逆序,保证其原始顺序
long startLine = DataConvertHelper.toLong(data.getRequest("sline"), -1);
long endLine = DataConvertHelper.toLong(data.getRequest("eline"), -1);
if (startLine == -1 && endLine > -1) {
Collections.reverse(records);
}
data.putResponse("rs", JSONHelper.toString(records));
// 返回总条数
data.putResponse("count", shits.getTotalHits() + "");
}
示例8: testScrollAndUpdateIndex
import org.elasticsearch.search.SearchHit; //导入方法依赖的package包/类
public void testScrollAndUpdateIndex() throws Exception {
client().admin().indices().prepareCreate("test").setSettings(Settings.builder().put("index.number_of_shards", 5)).execute().actionGet();
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
for (int i = 0; i < 500; i++) {
client().prepareIndex("test", "tweet", Integer.toString(i)).setSource(
jsonBuilder().startObject().field("user", "kimchy").field("postDate", System.currentTimeMillis()).field("message", "test").endObject()).execute().actionGet();
}
client().admin().indices().prepareRefresh().execute().actionGet();
assertThat(client().prepareSearch().setSize(0).setQuery(matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(500L));
assertThat(client().prepareSearch().setSize(0).setQuery(termQuery("message", "test")).execute().actionGet().getHits().getTotalHits(), equalTo(500L));
assertThat(client().prepareSearch().setSize(0).setQuery(termQuery("message", "test")).execute().actionGet().getHits().getTotalHits(), equalTo(500L));
assertThat(client().prepareSearch().setSize(0).setQuery(termQuery("message", "update")).execute().actionGet().getHits().getTotalHits(), equalTo(0L));
assertThat(client().prepareSearch().setSize(0).setQuery(termQuery("message", "update")).execute().actionGet().getHits().getTotalHits(), equalTo(0L));
SearchResponse searchResponse = client().prepareSearch()
.setQuery(queryStringQuery("user:kimchy"))
.setSize(35)
.setScroll(TimeValue.timeValueMinutes(2))
.addSort("postDate", SortOrder.ASC)
.execute().actionGet();
try {
do {
for (SearchHit searchHit : searchResponse.getHits().getHits()) {
Map<String, Object> map = searchHit.getSourceAsMap();
map.put("message", "update");
client().prepareIndex("test", "tweet", searchHit.getId()).setSource(map).execute().actionGet();
}
searchResponse = client().prepareSearchScroll(searchResponse.getScrollId()).setScroll(TimeValue.timeValueMinutes(2)).execute().actionGet();
} while (searchResponse.getHits().getHits().length > 0);
client().admin().indices().prepareRefresh().execute().actionGet();
assertThat(client().prepareSearch().setSize(0).setQuery(matchAllQuery()).execute().actionGet().getHits().getTotalHits(), equalTo(500L));
assertThat(client().prepareSearch().setSize(0).setQuery(termQuery("message", "test")).execute().actionGet().getHits().getTotalHits(), equalTo(0L));
assertThat(client().prepareSearch().setSize(0).setQuery(termQuery("message", "test")).execute().actionGet().getHits().getTotalHits(), equalTo(0L));
assertThat(client().prepareSearch().setSize(0).setQuery(termQuery("message", "update")).execute().actionGet().getHits().getTotalHits(), equalTo(500L));
assertThat(client().prepareSearch().setSize(0).setQuery(termQuery("message", "update")).execute().actionGet().getHits().getTotalHits(), equalTo(500L));
} finally {
clearScroll(searchResponse.getScrollId());
}
}
示例9: getSearchFilmes
import org.elasticsearch.search.SearchHit; //导入方法依赖的package包/类
public List<Map<String, Object>> getSearchFilmes(String titulo, String desc, Integer ano) {
List<Map<String, Object>> filmes = new ArrayList<Map<String, Object>>();
// Seu código deve vir daqui para baixo
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
if (!StringUtils.isEmpty(titulo)) boolQueryBuilder.must().add(QueryBuilders.matchQuery("title", titulo));
if (!StringUtils.isEmpty(desc)) boolQueryBuilder.must().add(QueryBuilders.matchQuery("overview", desc));
if (ano != null && ano <= Calendar.getInstance().get(Calendar.YEAR)) {
boolQueryBuilder.must().add(QueryBuilders.rangeQuery("release_date").gte(ano + "||/y").lte("now/y").format("yyyy"));
}
SearchResponse response = client.prepareSearch(INDEX).setTypes(TYPE)
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(boolQueryBuilder)
.execute().actionGet();
SearchHit[] results = response.getHits().getHits();
for (SearchHit hit : results) {
System.out.println("------------------------------");
Map<String, Object> result = hit.getSourceAsMap();
filmes.add(result);
System.out.println(result);
}
return filmes;
}