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


Java QueryBuilders.queryStringQuery方法代码示例

本文整理汇总了Java中org.elasticsearch.index.query.QueryBuilders.queryStringQuery方法的典型用法代码示例。如果您正苦于以下问题:Java QueryBuilders.queryStringQuery方法的具体用法?Java QueryBuilders.queryStringQuery怎么用?Java QueryBuilders.queryStringQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.index.query.QueryBuilders的用法示例。


在下文中一共展示了QueryBuilders.queryStringQuery方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createConfig

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的package包/类
public static LogcenterConfig createConfig(JSONObject jsonInput) throws LogConsumerException {
    String productLine = String.valueOf(jsonInput.get("productLine"));
    String appName = String.valueOf(jsonInput.get("appName"));
    QueryBuilder qb = QueryBuilders.queryStringQuery("productLine:'" + productLine + "' AND appName:'" + appName + "'");
    SearchResponse response = ElasticsearchClient.getClient()
            .prepareSearch(Constants.METADATA_INDEX)
            .setTypes(Constants.METADATA_TYPE)
            .setQuery(qb)
            .get();
    JSONObject jsonObject = JSON.parseObject(response.toString());
    JSONArray hitArray = (JSONArray) jsonObject.getJSONObject("hits").get("hits");
    if (hitArray.size() == 0) {
        throw new LogConsumerException("index does not exist,please check the configuration of the .logcenter index");
    }
    JSONObject document = (JSONObject) hitArray.get(0);
    String jsonStr = document.get("_source").toString();

    return JSONObject.parseObject(jsonStr, LogcenterConfig.class);
}
 
开发者ID:geeker-lait,项目名称:tasfe-framework,代码行数:20,代码来源:LogConfigFactory.java

示例2: urlParamsToQueryBuilder

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的package包/类
public static QueryBuilder urlParamsToQueryBuilder(RestRequest request) {
    String queryString = request.param("q");
    if (queryString == null) {
        return null;
    }
    QueryStringQueryBuilder queryBuilder = QueryBuilders.queryStringQuery(queryString);
    queryBuilder.defaultField(request.param("df"));
    queryBuilder.analyzer(request.param("analyzer"));
    queryBuilder.analyzeWildcard(request.paramAsBoolean("analyze_wildcard", false));
    queryBuilder.lenient(request.paramAsBoolean("lenient", null));
    String defaultOperator = request.param("default_operator");
    if (defaultOperator != null) {
        queryBuilder.defaultOperator(Operator.fromString(defaultOperator));
    }
    return queryBuilder;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:RestActions.java

示例3: elasticSearch

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的package包/类
private static void elasticSearch(JestClient client, String indexName, String type, String query) {
	SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
	QueryStringQueryBuilder queryStringQueryBuilder = QueryBuilders.queryStringQuery(query);
	searchSourceBuilder.query(queryStringQueryBuilder);
	Search searchElastic = (Search) new Search.Builder(searchSourceBuilder.toString())
			// multiple index or types can be added.
			.addIndex(indexName).addType(type).build();

	try {
		SearchResult elasticRs = client.execute(searchElastic);

		List<Hit<Article, Void>> hits = elasticRs.getHits(Article.class);
		for (Hit<Article, Void> hit : hits) {
			Article talk = hit.source;
			System.out.println("Elastic hits: " + talk.toString());
		}
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
开发者ID:conorheffron,项目名称:elastic-tester,代码行数:21,代码来源:ElasticApp.java

示例4: parseQuerySource

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的package包/类
public static QuerySourceBuilder parseQuerySource(RestRequest request) {
    String queryString = request.param("q");
    if (queryString == null) {
        return null;
    }
    QueryStringQueryBuilder queryBuilder = QueryBuilders.queryStringQuery(queryString);
    queryBuilder.defaultField(request.param("df"));
    queryBuilder.analyzer(request.param("analyzer"));
    queryBuilder.analyzeWildcard(request.paramAsBoolean("analyze_wildcard", false));
    queryBuilder.lowercaseExpandedTerms(request.paramAsBoolean("lowercase_expanded_terms", true));
    queryBuilder.lenient(request.paramAsBoolean("lenient", null));
    String defaultOperator = request.param("default_operator");
    if (defaultOperator != null) {
        if ("OR".equals(defaultOperator)) {
            queryBuilder.defaultOperator(QueryStringQueryBuilder.Operator.OR);
        } else if ("AND".equals(defaultOperator)) {
            queryBuilder.defaultOperator(QueryStringQueryBuilder.Operator.AND);
        } else {
            throw new IllegalArgumentException("Unsupported defaultOperator [" + defaultOperator + "], can either be [OR] or [AND]");
        }
    }
    return new QuerySourceBuilder().setQuery(queryBuilder);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:24,代码来源:RestActions.java

示例5: testForClient

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的package包/类
@Test
public void testForClient() throws Exception {
    QueryBuilder qb = QueryBuilders.queryStringQuery("+kimchy -elasticsearch");
    client.prepareSearch().setQuery(qb).execute().actionGet();
}
 
开发者ID:felayman,项目名称:elasticsearch-full,代码行数:6,代码来源:QueryStringQueryDemo.java

示例6: queryForObject

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的package包/类
/**
 * 查询返回一个Map对象
 *
 * @param esIndexName
 * @param type
 * @param fields
 * @param content
 * @param sortField
 * @param order
 * @param from
 * @param size
 * @return
 */

public List<Map<String, Object>> queryForObject(String esIndexName, String type, String[] fields, String content, String sortField, SortOrder order, List<String> heightFields, int from, int size) {
    SearchRequestBuilder reqBuilder = esClient.prepareSearch(esIndexName)
            .setTypes(type).setSearchType(SearchType.DEFAULT)
            .setExplain(true);
    QueryStringQueryBuilder queryString = QueryBuilders.queryStringQuery("\"" + content + "\"");
    for (String k : fields) {
        queryString.field(k);
    }
    queryString.minimumShouldMatch("10");
    reqBuilder.setExplain(true);

    reqBuilder.setQuery(QueryBuilders.boolQuery().should(queryString))
            .setExplain(true);
    if (StringUtils.isNotEmpty(sortField) && order != null) {
        reqBuilder.addSort(sortField, order);
    }
    if (from >= 0 && size > 0) {
        reqBuilder.setFrom(from).setSize(size);
    }
    //设置高亮显示
    if (heightFields != null) {
        for (String hs : heightFields)
            reqBuilder.addHighlightedField(hs);
    }
    reqBuilder.setHighlighterPreTags("<span style=\"color:red\">");
    reqBuilder.setHighlighterPostTags("</span>");
    SearchResponse resp = reqBuilder.execute().actionGet();
    SearchHit[] hits = resp.getHits().getHits();

    List<Map<String, Object>> results = new ArrayList<Map<String, Object>>();
    for (SearchHit hit : hits) {
        Map<String, Object> map = new HashMap<String, Object>();
        for (String key : hit.getSource().keySet()) {
            if (heightFields != null && heightFields.contains(key)) {
                map.put(key, hit.getHighlightFields().get(key).fragments()[0]);
            } else
                map.put(key, hit.getSource().get(key));

        }
        results.add(map);
    }
    return results;
}
 
开发者ID:aillamsun,项目名称:spring-boot-elastcsearch-example,代码行数:58,代码来源:EsNotEntityDao.java


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