Search in sources :

Example 71 with QueryBuilder

use of org.elasticsearch.index.query.QueryBuilder in project metron by apache.

the class ElasticsearchMetaAlertDao method getAllAlertsForMetaAlert.

@SuppressWarnings("unchecked")
protected List<Map<String, Object>> getAllAlertsForMetaAlert(Document update) throws IOException {
    Document latest = indexDao.getLatest(update.getGuid(), MetaAlertDao.METAALERT_TYPE);
    if (latest == null) {
        return new ArrayList<>();
    }
    List<String> guids = new ArrayList<>();
    List<Map<String, Object>> latestAlerts = (List<Map<String, Object>>) latest.getDocument().get(MetaAlertDao.ALERT_FIELD);
    for (Map<String, Object> alert : latestAlerts) {
        guids.add((String) alert.get(Constants.GUID));
    }
    List<Map<String, Object>> alerts = new ArrayList<>();
    QueryBuilder query = QueryBuilders.idsQuery().addIds(guids.toArray(new String[0]));
    SearchRequestBuilder request = elasticsearchDao.getClient().prepareSearch().setQuery(query);
    org.elasticsearch.action.search.SearchResponse response = request.get();
    for (SearchHit hit : response.getHits().getHits()) {
        alerts.add(hit.sourceAsMap());
    }
    return alerts;
}
Also used : SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) SearchHit(org.elasticsearch.search.SearchHit) QueryStringQueryBuilder(org.elasticsearch.index.query.QueryStringQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) Document(org.apache.metron.indexing.dao.update.Document)

Example 72 with QueryBuilder

use of org.elasticsearch.index.query.QueryBuilder in project metacat by Netflix.

the class ElasticSearchUtilImpl method getIdsByQualifiedName.

/**
 * {@inheritDoc}
 */
@Override
public List<String> getIdsByQualifiedName(final String type, final QualifiedName qualifiedName) {
    List<String> result = Lists.newArrayList();
    // Run the query and get the response.
    final QueryBuilder queryBuilder = QueryBuilders.boolQuery().must(QueryBuilders.termQuery("name.qualifiedName.tree", qualifiedName)).must(QueryBuilders.termQuery("deleted_", false));
    final SearchRequestBuilder request = client.prepareSearch(esIndex).setTypes(type).setSearchType(SearchType.QUERY_THEN_FETCH).setQuery(queryBuilder).setSize(Integer.MAX_VALUE).setFetchSource(false);
    final SearchResponse response = request.execute().actionGet();
    if (response.getHits().getHits().length != 0) {
        result = getIds(response);
    }
    return result;
}
Also used : SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 73 with QueryBuilder

use of org.elasticsearch.index.query.QueryBuilder in project fess by codelibs.

the class ApiAdminSearchlistAction method delete$doc.

// DELETE /api/admin/searchlist/doc/{id}
@Execute
public JsonResponse<ApiResult> delete$doc(final String id) {
    try {
        final QueryBuilder query = QueryBuilders.termQuery(fessConfig.getIndexFieldDocId(), id);
        fessEsClient.deleteByQuery(fessConfig.getIndexDocumentUpdateIndex(), fessConfig.getIndexDocumentType(), query);
        saveInfo(messages -> messages.addSuccessDeleteDocFromIndex(GLOBAL));
    } catch (final Exception e) {
        throwValidationErrorApi(messages -> messages.addErrorsFailedToDeleteDocInAdmin(GLOBAL));
    }
    return asJson(new ApiResponse().status(Status.OK).result());
}
Also used : Constants(org.codelibs.fess.Constants) AdminSearchlistAction.validateUpdateFields(org.codelibs.fess.app.web.admin.searchlist.AdminSearchlistAction.validateUpdateFields) AdminSearchlistAction.getDoc(org.codelibs.fess.app.web.admin.searchlist.AdminSearchlistAction.getDoc) LoggerFactory(org.slf4j.LoggerFactory) ApiDeleteResponse(org.codelibs.fess.app.web.api.ApiResult.ApiDeleteResponse) ResultOffsetExceededException(org.codelibs.fess.exception.ResultOffsetExceededException) QueryBuilders(org.elasticsearch.index.query.QueryBuilders) ApiResult(org.codelibs.fess.app.web.api.ApiResult) Status(org.codelibs.fess.app.web.api.ApiResult.Status) CrudMode(org.codelibs.fess.app.web.CrudMode) Map(java.util.Map) ApiResponse(org.codelibs.fess.app.web.api.ApiResult.ApiResponse) SearchRenderData(org.codelibs.fess.entity.SearchRenderData) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) AdminSearchlistAction.validateCreateFields(org.codelibs.fess.app.web.admin.searchlist.AdminSearchlistAction.validateCreateFields) Logger(org.slf4j.Logger) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) FessEsClient(org.codelibs.fess.es.client.FessEsClient) ApiDocResponse(org.codelibs.fess.app.web.api.ApiResult.ApiDocResponse) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) JsonResponse(org.lastaflute.web.response.JsonResponse) ApiUpdateResponse(org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse) SearchService(org.codelibs.fess.app.service.SearchService) ComponentUtil(org.codelibs.fess.util.ComponentUtil) ApiDocsResponse(org.codelibs.fess.app.web.api.ApiResult.ApiDocsResponse) Execute(org.lastaflute.web.Execute) InvalidQueryException(org.codelibs.fess.exception.InvalidQueryException) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) ResultOffsetExceededException(org.codelibs.fess.exception.ResultOffsetExceededException) InvalidQueryException(org.codelibs.fess.exception.InvalidQueryException) ApiResponse(org.codelibs.fess.app.web.api.ApiResult.ApiResponse) Execute(org.lastaflute.web.Execute)

Example 74 with QueryBuilder

use of org.elasticsearch.index.query.QueryBuilder in project fess by codelibs.

the class EsAbstractConditionQuery method regRangeQ.

protected RangeQueryBuilder regRangeQ(String name, ConditionKey ck, Object value) {
    checkEsInvalidQuery(name, value);
    assertObjectNotNull("ck", ck);
    if (queryBuilderList != null) {
        for (QueryBuilder builder : queryBuilderList) {
            if (builder instanceof RangeQueryBuilder) {
                RangeQueryBuilder rangeQueryBuilder = (RangeQueryBuilder) builder;
                if (rangeQueryBuilder.toString().replaceAll("\\s", "").startsWith("{\"range\":{\"" + name + "\"")) {
                    addRangeC(rangeQueryBuilder, ck, value);
                    return rangeQueryBuilder;
                }
            }
        }
    }
    RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery(name);
    addRangeC(rangeQueryBuilder, ck, value);
    regQ(rangeQueryBuilder);
    return rangeQueryBuilder;
}
Also used : IdsQueryBuilder(org.elasticsearch.index.query.IdsQueryBuilder) MatchQueryBuilder(org.elasticsearch.index.query.MatchQueryBuilder) RegexpQueryBuilder(org.elasticsearch.index.query.RegexpQueryBuilder) PrefixQueryBuilder(org.elasticsearch.index.query.PrefixQueryBuilder) QueryStringQueryBuilder(org.elasticsearch.index.query.QueryStringQueryBuilder) TermsQueryBuilder(org.elasticsearch.index.query.TermsQueryBuilder) MatchPhrasePrefixQueryBuilder(org.elasticsearch.index.query.MatchPhrasePrefixQueryBuilder) CommonTermsQueryBuilder(org.elasticsearch.index.query.CommonTermsQueryBuilder) FunctionScoreQueryBuilder(org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder) SpanTermQueryBuilder(org.elasticsearch.index.query.SpanTermQueryBuilder) MoreLikeThisQueryBuilder(org.elasticsearch.index.query.MoreLikeThisQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) RangeQueryBuilder(org.elasticsearch.index.query.RangeQueryBuilder) WildcardQueryBuilder(org.elasticsearch.index.query.WildcardQueryBuilder) ExistsQueryBuilder(org.elasticsearch.index.query.ExistsQueryBuilder) TermQueryBuilder(org.elasticsearch.index.query.TermQueryBuilder) MatchPhraseQueryBuilder(org.elasticsearch.index.query.MatchPhraseQueryBuilder) MatchAllQueryBuilder(org.elasticsearch.index.query.MatchAllQueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) RangeQueryBuilder(org.elasticsearch.index.query.RangeQueryBuilder)

Example 75 with QueryBuilder

use of org.elasticsearch.index.query.QueryBuilder in project elasticsearch by elastic.

the class AliasValidator method validateAliasFilter.

private static void validateAliasFilter(XContentParser parser, QueryShardContext queryShardContext) throws IOException {
    QueryParseContext queryParseContext = queryShardContext.newParseContext(parser);
    QueryBuilder parseInnerQueryBuilder = queryParseContext.parseInnerQueryBuilder();
    QueryBuilder queryBuilder = QueryBuilder.rewriteQuery(parseInnerQueryBuilder, queryShardContext);
    queryBuilder.toFilter(queryShardContext);
}
Also used : QueryParseContext(org.elasticsearch.index.query.QueryParseContext) QueryBuilder(org.elasticsearch.index.query.QueryBuilder)

Aggregations

QueryBuilder (org.elasticsearch.index.query.QueryBuilder)161 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)51 SearchResponse (org.elasticsearch.action.search.SearchResponse)32 MatchAllQueryBuilder (org.elasticsearch.index.query.MatchAllQueryBuilder)25 Map (java.util.Map)22 ArrayList (java.util.ArrayList)19 AbstractQueryBuilder (org.elasticsearch.index.query.AbstractQueryBuilder)19 RangeQueryBuilder (org.elasticsearch.index.query.RangeQueryBuilder)19 MatchQueryBuilder (org.elasticsearch.index.query.MatchQueryBuilder)18 HashMap (java.util.HashMap)16 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)16 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)14 HasParentQueryBuilder (org.elasticsearch.index.query.HasParentQueryBuilder)14 TermQueryBuilder (org.elasticsearch.index.query.TermQueryBuilder)14 FunctionScoreQueryBuilder (org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder)14 IOException (java.io.IOException)12 FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)12 MultiSearchResponse (org.elasticsearch.action.search.MultiSearchResponse)11 XContentParser (org.elasticsearch.common.xcontent.XContentParser)11 BytesRef (org.apache.lucene.util.BytesRef)10