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;
}
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;
}
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());
}
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;
}
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);
}
Aggregations