本文整理汇总了Java中org.elasticsearch.index.query.BoolQueryBuilder.filter方法的典型用法代码示例。如果您正苦于以下问题:Java BoolQueryBuilder.filter方法的具体用法?Java BoolQueryBuilder.filter怎么用?Java BoolQueryBuilder.filter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.index.query.BoolQueryBuilder
的用法示例。
在下文中一共展示了BoolQueryBuilder.filter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: preparse
import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
private QueryBuilder preparse(String q, int timezoneOffset) {
// detect usage of OR connector usage.
q = fixQueryMistakes(q);
List<String> terms = splitIntoORGroups(q); // OR binds stronger than AND
if (terms.size() == 0) return QueryBuilders.constantScoreQuery(QueryBuilders.matchAllQuery());
// special handling
if (terms.size() == 1) return parse(terms.get(0), timezoneOffset);
// generic handling
BoolQueryBuilder aquery = QueryBuilders.boolQuery();
for (String t: terms) {
QueryBuilder partial = parse(t, timezoneOffset);
aquery.filter(partial);
}
return aquery;
}
示例2: applyAccessControlQuery
import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
private void applyAccessControlQuery(FactSearchCriteria criteria, BoolQueryBuilder rootQuery) {
// Query to verify that user has access to Fact ...
BoolQueryBuilder accessQuery = boolQuery()
// ... if Fact is public.
.should(termQuery("accessMode", FactDocument.AccessMode.Public))
// ... if AccessMode == Explicit user must be in ACL.
.should(boolQuery()
.filter(termQuery("accessMode", FactDocument.AccessMode.Explicit))
.filter(termQuery("acl", criteria.getCurrentUserID()))
)
// ... if AccessMode == RoleBased user must be in ACL or have access to the owning Organization.
.should(boolQuery()
.filter(termQuery("accessMode", FactDocument.AccessMode.RoleBased))
.filter(boolQuery()
.should(termQuery("acl", criteria.getCurrentUserID()))
.should(termsQuery("organizationID", criteria.getAvailableOrganizationID()))
)
);
// Always apply access control query.
rootQuery.filter(accessQuery);
}
示例3: applyFieldStrategy
import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
private void applyFieldStrategy(BoolQueryBuilder rootQuery, Function<String, QueryBuilder> fieldQueryResolver,
Set<? extends FactSearchCriteria.FieldStrategy> fieldStrategies,
FactSearchCriteria.MatchStrategy matchStrategy) {
// Determine all fields to query.
Set<String> fieldsToQuery = fieldStrategies.stream()
.flatMap(strategy -> strategy.getFields().stream())
.collect(Collectors.toSet());
BoolQueryBuilder strategyQuery = boolQuery();
for (String field : fieldsToQuery) {
if (matchStrategy == FactSearchCriteria.MatchStrategy.all) {
// Field query must match all fields.
strategyQuery.filter(fieldQueryResolver.apply(field));
} else {
// Field query should match at least one field.
strategyQuery.should(fieldQueryResolver.apply(field));
}
}
rootQuery.filter(strategyQuery);
}
示例4: toQuery
import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
private BoolSearch toQuery(Context context) {
BoolQueryBuilder query = QueryBuilders.boolQuery()//
.filter(QueryBuilders.termQuery(FIELD_BACKEND_ID, SpaceContext.backendId()));
String username = context.get(FIELD_USERNAME);
if (!Strings.isNullOrEmpty(username))
query.filter(QueryBuilders.termQuery(FIELD_USERNAME, username));
String email = context.get(FIELD_EMAIL);
if (!Strings.isNullOrEmpty(email))
query.filter(QueryBuilders.termQuery(FIELD_EMAIL, email));
String level = context.get(FIELD_CREDENTIALS_LEVEL);
if (!Strings.isNullOrEmpty(level))
query.filter(QueryBuilders.termQuery(FIELD_CREDENTIALS_LEVEL, level));
BoolSearch search = new BoolSearch(SPACEDOG_BACKEND, TYPE, query, //
context.query().getInteger(PARAM_FROM, 0), //
context.query().getInteger(PARAM_SIZE, 10));
return search;
}
示例5: doPurgeBackend
import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
private Optional<DeleteByQueryResponse> doPurgeBackend(DateTime before, //
Optional<String> optBackendId) {
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery()//
.filter(QueryBuilders.rangeQuery(FIELD_RECEIVED_AT).lt(before.toString()));
if (optBackendId.isPresent())
boolQueryBuilder.filter(//
QueryBuilders.termQuery("credentials.backendId", optBackendId.get()));
String query = new QuerySourceBuilder().setQuery(boolQueryBuilder).toString();
DeleteByQueryResponse delete = Start.get().getElasticClient()//
.deleteByQuery(query, SPACEDOG_BACKEND, TYPE);
// TODO why return an optional?
// return directly the response
return Optional.of(delete);
}
示例6: doGetLogs
import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
private SearchResponse doGetLogs(int from, int size, Optional<String> backendId) {
BoolQueryBuilder query = QueryBuilders.boolQuery();
if (backendId.isPresent())
query.filter(QueryBuilders.termQuery("credentials.backendId", backendId.get()));
return Start.get().getElasticClient()//
.prepareSearch(SPACEDOG_BACKEND, TYPE)//
.setTypes(TYPE)//
.setQuery(query)//
.addSort(FIELD_RECEIVED_AT, SortOrder.DESC)//
.setFrom(from)//
.setSize(size)//
.get();
}
示例7: queryWithConstraints
import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的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;
}
示例8: query
import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
@Override
public Object query(Person person) {
List<Map<String, Object>> result = new ArrayList<>();
try {
BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
if (person.getName() != null) {
// boolBuilder.must(QueryBuilders.matchQuery("name", person.getName()));
boolBuilder.should(QueryBuilders.matchQuery("name", person.getName()));
}
if (person.getIntroduce() != null) {
// boolBuilder.must(QueryBuilders.matchQuery("introduce", person.getIntroduce()));
boolBuilder.should(QueryBuilders.matchQuery("introduce", person.getIntroduce()));
}
//大于age,小于age+10
if (person.getAge() > 0) {
RangeQueryBuilder rangeQuery = QueryBuilders.rangeQuery("age");
rangeQuery.from(person.getAge());
rangeQuery.to(person.getAge() + 10);
boolBuilder.filter(rangeQuery);
}
SearchRequestBuilder builder = transportClient.prepareSearch(index)
.setTypes(type)
.setSearchType(SearchType.QUERY_THEN_FETCH)
.setQuery(boolBuilder)
.setFrom(0)
.setSize(10);
log.info(String.valueOf(builder));
SearchResponse response = builder.get();
response.getHits().forEach((s) -> result.add(s.getSource()));
} catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage(), e);
}
return result;
}
示例9: search
import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
public SearchHits search(String backendId, String type, Object... terms) {
if (terms.length % 2 == 1)
throw Exceptions.illegalArgument(//
"invalid search terms %s: missing term value", Arrays.toString(terms));
BoolQueryBuilder builder = QueryBuilders.boolQuery();
for (int i = 0; i < terms.length; i = i + 2)
builder.filter(QueryBuilders.termQuery(terms[i].toString(), terms[i + 1]));
SearchResponse response = Start.get().getElasticClient()//
.prepareSearch(backendId, type).setTypes(type).setQuery(builder).get();
return response.getHits();
}
示例10: applySimpleFilterQueries
import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
private void applySimpleFilterQueries(FactSearchCriteria criteria, BoolQueryBuilder rootQuery) {
if (!CollectionUtils.isEmpty(criteria.getFactID())) {
rootQuery.filter(termsQuery("_id", criteria.getFactID()));
}
if (!CollectionUtils.isEmpty(criteria.getFactTypeID())) {
rootQuery.filter(termsQuery("typeID", criteria.getFactTypeID()));
}
if (!CollectionUtils.isEmpty(criteria.getFactTypeName())) {
rootQuery.filter(termsQuery("typeName", criteria.getFactTypeName()));
}
if (!CollectionUtils.isEmpty(criteria.getFactValue())) {
rootQuery.filter(termsQuery("value", criteria.getFactValue()));
}
if (!CollectionUtils.isEmpty(criteria.getInReferenceTo())) {
rootQuery.filter(termsQuery("inReferenceTo", criteria.getInReferenceTo()));
}
if (!CollectionUtils.isEmpty(criteria.getOrganizationID())) {
rootQuery.filter(termsQuery("organizationID", criteria.getOrganizationID()));
}
if (!CollectionUtils.isEmpty(criteria.getOrganizationName())) {
rootQuery.filter(termsQuery("organizationName", criteria.getOrganizationName()));
}
if (!CollectionUtils.isEmpty(criteria.getSourceID())) {
rootQuery.filter(termsQuery("sourceID", criteria.getSourceID()));
}
if (!CollectionUtils.isEmpty(criteria.getSourceName())) {
rootQuery.filter(termsQuery("sourceName", criteria.getSourceName()));
}
if (!CollectionUtils.isEmpty(criteria.getObjectID())) {
rootQuery.filter(nestedQuery("objects", termsQuery("objects.id", criteria.getObjectID()), ScoreMode.None));
}
if (!CollectionUtils.isEmpty(criteria.getObjectTypeID())) {
rootQuery.filter(nestedQuery("objects", termsQuery("objects.typeID", criteria.getObjectTypeID()), ScoreMode.None));
}
if (!CollectionUtils.isEmpty(criteria.getObjectTypeName())) {
rootQuery.filter(nestedQuery("objects", termsQuery("objects.typeName", criteria.getObjectTypeName()), ScoreMode.None));
}
if (!CollectionUtils.isEmpty(criteria.getObjectValue())) {
rootQuery.filter(nestedQuery("objects", termsQuery("objects.value", criteria.getObjectValue()), ScoreMode.None));
}
if (criteria.getRetracted() != null) {
rootQuery.filter(termQuery("retracted", (boolean) criteria.getRetracted()));
}
}
示例11: version
import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
@GET
@Path("version")
@Produces(APPLICATION_JSON)
public List<RundeckXO> version(
@DefaultValue("10") @QueryParam("l") int limit,
@QueryParam("r") String repository,
@QueryParam("g") String groupId,
@QueryParam("a") String artifactId,
@QueryParam("c") String classifier,
@QueryParam("p") String extension
) {
log.debug("param value, repository: {}, limit: {}, groupId: {}, artifactId: {}, classifier: {}, extension: {}", repository, limit, groupId, artifactId, classifier, extension);
BoolQueryBuilder query = boolQuery();
query.filter(termQuery("format", "maven2"));
if (!isBlank(repository)) {
query.filter(termQuery("repository_name", repository));
}
if (!isBlank(groupId)) {
query.filter(termQuery("attributes.maven2.groupId", groupId));
}
if (!isBlank(artifactId)) {
query.filter(termQuery("attributes.maven2.artifactId", artifactId));
}
if (!isBlank(classifier)) {
query.filter(termQuery("assets.attributes.maven2.classifier", classifier));
}
if (!isBlank(extension)) {
query.filter(termQuery("assets.attributes.maven2.extension", extension));
}
log.debug("rundeck maven version query: {}", query);
SearchResponse result = searchService.search(
query,
Collections.singletonList(new FieldSortBuilder("assets.attributes.content.last_modified").order(SortOrder.DESC)),
0,
limit
);
return Arrays.stream(result.getHits().hits())
.map(this::his2RundeckXO)
.collect(Collectors.toList());
}
示例12: search
import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
@Override
public Collection<AddOnInfoSummary> search(AddOnType type, String query, String tag) throws IOException {
BoolQueryBuilder boolQB = QueryBuilders.boolQuery();
if (type != null) {
//Exact match on type
boolQB.filter(QueryBuilders.matchQuery("type", type));
}
if (tag != null) {
boolQB.filter(QueryBuilders.matchQuery("tags", tag));
}
if (query != null) {
//Exact match on id(Highest priority)
boolQB.should(QueryBuilders.termQuery("_id", query).boost(1700.0f));
//Exact match on tag(High priority)
boolQB.should(QueryBuilders.termQuery("tags", query).boost(1500.0f));
//Prefix match of module name(Medium priority)
boolQB.should(QueryBuilders.prefixQuery("name", query).boost(4.0f));
//Query is subset of module name(Medium priority)
boolQB.should(QueryBuilders.matchQuery("name", query).boost(2.0f));
//Description matches query either completely or partially(Low priority)
boolQB.should(QueryBuilders.matchQuery("description", query).boost(0.5f));
//Allow for spelling mistake while searching for a particular module
boolQB.should(QueryBuilders.matchPhraseQuery("name", query).slop(2).fuzziness("AUTO"));
boolQB.minimumNumberShouldMatch(1);
}
BoostingQueryBuilder boostingQB = QueryBuilders.boostingQuery();
boostingQB.positive(boolQB);
//Decrease ranking of those modules which are "Deprecated" or "Inactive"
boostingQB.negative(QueryBuilders.termsQuery("status", "DEPRECATED", "INACTIVE"));
boostingQB.negativeBoost(0.01f);
SearchResult result = client.execute(new Search.Builder(
new SearchSourceBuilder().size(SEARCH_SIZE).query(boostingQB).toString())
.addIndex(AddOnInfoAndVersions.ES_INDEX)
.build());
return result.getHits(AddOnInfoAndVersions.class).stream()
.map(sr -> new AddOnInfoSummary(sr.source))
.collect(Collectors.toList());
}
示例13: buildAllThings
import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
private QueryBuilder buildAllThings(String query, String motivations, String allDateRanges, String users,
String type, String within) {
List<QueryBuilder> queryList = new ArrayList<>();
BoolQueryBuilder must = QueryBuilders.boolQuery();
if (null != query) {
// String tidyQuery =
// annotationUtils.convertSpecialCharacters(query);
String tidyQuery = query;
if (null == type) {
must = must.must(QueryBuilders.multiMatchQuery(tidyQuery, "body", "target", "bodyURI", "targetURI")
.type(Type.PHRASE));
}
if ("topic".equals(type)) {
must = must.must(QueryBuilders.multiMatchQuery(tidyQuery, "bodyURI"));
}
}
if (null != motivations) {
List<String> motivationsList = annotationUtils.getListFromSpaceSeparatedTerms(motivations);
if (motivations.contains("non-")) {
if (motivationsList.size() > 1) {
throw new SearchQueryException(
"You have a motivation that is a non-<motivation>, there can only be one motivation in this instance.");
} else {
String tidyMotivations = motivations.replaceAll("non-", "");
queryList.add(QueryBuilders.existsQuery(AnnotationSearchConstants.FIELD_MOTIVATIONS));
must.mustNot(QueryBuilders.termQuery(AnnotationSearchConstants.FIELD_MOTIVATIONS, tidyMotivations));
}
} else {
must.filter(QueryBuilders.termsQuery(AnnotationSearchConstants.FIELD_MOTIVATIONS, motivationsList));
}
}
if (null != allDateRanges) {
queryList.add(buildDates("created", allDateRanges));
}
if (null != users) {
List<String> usersList = annotationUtils.getListFromSpaceSeparatedTerms(users);
must.filter(QueryBuilders.termsQuery("creators", usersList));
}
for (QueryBuilder eachQuery : queryList) {
must = must.must(eachQuery);
}
if (null != within) {
String decodedWithinUrl = annotationUtils.decodeWithinUrl(within);
if (null != decodedWithinUrl) {
must.must(QueryBuilders.matchQuery("manifest", decodedWithinUrl));
}
}
return must;
}
示例14: contribute
import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
@Override
public void contribute(final BoolQueryBuilder query, final String type, final String value) {
if (value != null) {
query.filter(QueryBuilders.termQuery(type, value));
}
}
示例15: pushByTags
import org.elasticsearch.index.query.BoolQueryBuilder; //导入方法依赖的package包/类
/**
* Check this page for specific json messages:
* http://docs.aws.amazon.com/sns/latest/dg/mobile-push-send-custommessage.
* html
*/
@Post("/push")
@Post("/push/")
@Post("/installation/push")
@Post("/installation/push/")
public Payload pushByTags(String body, Context context) {
Credentials credentials = SpaceContext.checkUserCredentials();
ObjectNode push = Json8.readObject(body);
String appId = Json8.checkStringNotNullOrEmpty(push, APP_ID);
JsonNode message = Json8.checkNode(push, MESSAGE, true).get();
BadgeStrategy badge = getBadgeStrategy(push);
ObjectNode objectMessage = toObjectMessage(message);
BoolQueryBuilder query = QueryBuilders.boolQuery()//
.filter(QueryBuilders.termQuery(APP_ID, appId));
Optional<String> service = Json8.checkString(push, PUSH_SERVICE);
if (service.isPresent())
query.filter(QueryBuilders.termQuery(PUSH_SERVICE, service.get()));
boolean usersOnly = Json8.checkBoolean(push, USERS_ONLY, false);
if (usersOnly)
query.filter(QueryBuilders.existsQuery(USER_ID));
JsonNode tags = push.get(TAGS);
if (tags != null) {
Iterator<JsonNode> tagsIterator = tags.isObject()//
? Iterators.singletonIterator(tags) : tags.elements();
while (tagsIterator.hasNext()) {
JsonNode tag = tagsIterator.next();
query.filter(//
QueryBuilders.termQuery(//
toFieldPath(TAGS, TAG_KEY), //
tag.get(TAG_KEY).asText()))//
.filter(QueryBuilders.termQuery(//
toFieldPath(TAGS, TAG_VALUE), //
tag.get(TAG_VALUE).asText()));
}
}
boolean refresh = context.query().getBoolean(PARAM_REFRESH, false);
DataStore.get().refreshType(refresh, credentials.backendId(), TYPE);
// TODO use a scroll to push to all installations found
SearchHits hits = Start.get().getElasticClient()//
.prepareSearch(credentials.backendId(), TYPE)//
.setQuery(query)//
.setFrom(0)//
.setSize(1000)//
.setVersion(false)//
.setFetchSource(new String[] { USER_ID, ENDPOINT, PUSH_SERVICE, BADGE }, null)//
.get()//
.getHits();
if (hits.totalHits() > 1000)
return JsonPayload.error(HttpStatus.NOT_IMPLEMENTED, //
"push to [%s] installations is a premium feature", hits.totalHits());
PushLog log = new PushLog();
for (SearchHit hit : hits.getHits()) {
ObjectNode installation = Json8.readObject(hit.sourceAsString());
pushToInstallation(log, hit.getId(), installation, objectMessage, credentials, badge);
if (log.applicationDisabled)
break;
}
return log.toPayload();
}