当前位置: 首页>>代码示例>>Java>>正文


Java SearchHit.getSourceAsMap方法代码示例

本文整理汇总了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;
	}
 
开发者ID:wilkerjmachado,项目名称:MoviesSearchPos,代码行数:21,代码来源:Filmes.java

示例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() + "");
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:31,代码来源:InvokeChainQueryHandler.java

示例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;
    }
 
开发者ID:uavorg,项目名称:uavstack,代码行数:17,代码来源:ThreadAnalysisQueryHandler.java

示例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;
}
 
开发者ID:yacy,项目名称:yacy_grid_mcp,代码行数:28,代码来源:ElasticsearchClient.java

示例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;
}
 
开发者ID:malike,项目名称:elasticsearch-report-engine,代码行数:18,代码来源:Generator.java

示例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() + "");
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:34,代码来源:SlowOperQueryHandler.java

示例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() + "");
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:32,代码来源:NewLogQueryHandler.java

示例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());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:44,代码来源:SearchScrollIT.java

示例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;
}
 
开发者ID:danillogontijo,项目名称:MoviesElasticsearchPos,代码行数:34,代码来源:Filmes.java


注:本文中的org.elasticsearch.search.SearchHit.getSourceAsMap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。