本文整理汇总了Java中org.elasticsearch.index.query.FilteredQueryBuilder类的典型用法代码示例。如果您正苦于以下问题:Java FilteredQueryBuilder类的具体用法?Java FilteredQueryBuilder怎么用?Java FilteredQueryBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FilteredQueryBuilder类属于org.elasticsearch.index.query包,在下文中一共展示了FilteredQueryBuilder类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMostRecentEntry
import org.elasticsearch.index.query.FilteredQueryBuilder; //导入依赖的package包/类
/**
* Gets the creation data of the single newest entry.
*
* @return ISO8601 formatted time of most recent entry, or null on empty or error.
*/
private String getMostRecentEntry() {
long totalEntries = client.prepareCount(index).setQuery(matchAllQuery()).execute().actionGet().getCount();
if (totalEntries > 0) {
FilteredQueryBuilder updatedAtQuery = QueryBuilders
.filteredQuery(QueryBuilders.matchAllQuery(), FilterBuilders.existsFilter("created_at"));
FieldSortBuilder updatedAtSort = SortBuilders.fieldSort("created_at").order(SortOrder.DESC);
SearchResponse response = client.prepareSearch(index)
.setQuery(updatedAtQuery)
.addSort(updatedAtSort)
.setSize(1)
.execute()
.actionGet();
String createdAt = (String) response.getHits().getAt(0).getSource().get("created_at");
logger.debug("Most recent event was created at {}", createdAt);
return createdAt;
} else {
// getData will get all data on a null.
logger.info("No existing entries, assuming first run");
return null;
}
}
示例2: deleteUnsupportedProjectEntries
import org.elasticsearch.index.query.FilteredQueryBuilder; //导入依赖的package包/类
@Test
public void deleteUnsupportedProjectEntries() {
String projectId="spring-framework";
List<String> supportedVersions = Arrays.asList("4.1.0.RELEASE","4.0.0.RELEASE");
String expected = "{" +
"\"query\":{" +
"\"filtered\":{" +
"\"query\":{\"match_all\":{}}," +
"\"filter\":{" +
"\"and\":{\"filters\":[" +
"{\"term\":{\"projectId\":\"spring-framework\"}}," +
"{\"not\":{\"filter\":{" +
"\"or\":{\"filters\":[" +
"{\"term\":{\"version\":\"4.1.0.RELEASE\"}}," +
"{\"term\":{\"version\":\"4.0.0.RELEASE\"}}" +
"]}" +
"}}}" +
"]}" +
"}" +
"}" +
"}}";
FilteredQueryBuilder builder = SaganQueryBuilders.matchUnsupportedProjectEntries(projectId, supportedVersions);
String result = SaganQueryBuilders.wrapQuery(builder.toString());
assertThat(result.replaceAll("[\\s|\\r|\\n]",""), equalTo(expected));
}
示例3: fetchAutoSuggestions
import org.elasticsearch.index.query.FilteredQueryBuilder; //导入依赖的package包/类
/**
* A method to create filtered query builder with appropriate filters to fetch auto suggestions.
*
* @param resourceRequest the resource request
* @param resourceResponse the resource response
* @throws IOException Signals that an I/O exception has occurred.
* @throws ElasticsearchAutocompleteException the elasticsearch autocomplete exception
*/
public void fetchAutoSuggestions(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
throws IOException, ElasticsearchAutocompleteException {
if (Validator.isNull(client)) {
throw new ElasticsearchAutocompleteException("Client object cannot be null.......");
}
if (_log.isDebugEnabled()) {
_log.debug("About to get suggestions from elasticsearch server.......");
}
String searchTerm = ParamUtil.getString(resourceRequest, ElasticsearchPortletConstants.SEARCH_TEXT);
QueryStringQueryBuilder stringQueryBuilder = QueryBuilders.queryString(searchTerm);
appendQueryFieldsToBuilder(stringQueryBuilder);
FilteredQueryBuilder filteredQueryBuilder = QueryBuilders.filteredQuery(stringQueryBuilder, prepareBoolFilterBuilder(resourceRequest));
requestBuilder.setQuery(filteredQueryBuilder);
SearchResponse response = requestBuilder.execute().actionGet();
PrintWriter out = resourceResponse.getWriter();
out.println(parseResponse(response));
if (_log.isDebugEnabled()) {
_log.debug("Suggestions retreived from elasticsearch server....");
}
}
开发者ID:rivetlogic,项目名称:liferay-elasticsearch-integration,代码行数:37,代码来源:ElasticsearchPortletHelper.java
示例4: testAddPercolator
import org.elasticsearch.index.query.FilteredQueryBuilder; //导入依赖的package包/类
@Test
public void testAddPercolator() throws Exception {
// Prepare: Setup Thrift Client and add some docs
populateWithTestDocs();
final FilterBuilder geoDistanceFilter =
new GeoDistanceFilterBuilder(TEST_TYPE + ".location").distance(10, DistanceUnit.KILOMETERS)
.lat(whiteHouse.getLocation().getLat()).lon(whiteHouse.getLocation().getLon());
final QueryBuilder filteredQuery = new FilteredQueryBuilder(QueryBuilders.matchAllQuery(), geoDistanceFilter);
final PercolateQuery percolator = new PercolateQuery();
percolator.setVisibility(new Visibility().setFormalVisibility("U"));
percolator.setId(UUID.randomUUID().toString());
final String queryDoc = jsonBuilder().startObject().field("query", filteredQuery).endObject().string();
percolator.setQueryDocument(queryDoc);
// Action: Create and execute an OR match query on title
final Document doc = new Document(
ElasticUtils.PERCOLATOR_TYPE, new Visibility().setFormalVisibility("U"), percolator.getQueryDocument());
final IndexResponse percolateResponse = client.put(Collections.singletonList(doc)).get(0);
assertTrue(percolateResponse.isSuccess());
// Assert: There should be 2 matching documents
oneaaNavyYardDoc.setPercolate(new PercolateRequest());
oneaaColumbiaDoc.setPercolate(new PercolateRequest());
whiteHouseDoc.setPercolate(new PercolateRequest());
washingtonMonumentDoc.setPercolate(new PercolateRequest());
final List<PercolateQuery> matches = client.percolate(
Arrays.asList(oneaaNavyYardDoc, oneaaColumbiaDoc, whiteHouseDoc, washingtonMonumentDoc));
assertEquals(3, matches.size());
}
示例5: testPercolator
import org.elasticsearch.index.query.FilteredQueryBuilder; //导入依赖的package包/类
@Test
public void testPercolator() throws Exception {
// Prepare: Setup Thrift Client and add some docs
client = pool.getClient(SERVICE_NAME, EzElastic.Client.class);
client.setTypeMapping(TEST_TYPE, getMappingForTest(), fakeSecurity);
client.bulkPut(
Arrays.asList(washingtonMonumentDoc, whiteHouseDoc, oneaaColumbiaDoc, oneaaNavyYardDoc), fakeSecurity);
final FilterBuilder geoDistanceFilter =
new GeoDistanceFilterBuilder(TEST_TYPE + ".location").distance(10, DistanceUnit.KILOMETERS)
.lat(whiteHouse.getLocation().getLat()).lon(whiteHouse.getLocation().getLon());
final QueryBuilder filteredQuery = new FilteredQueryBuilder(QueryBuilders.matchAllQuery(), geoDistanceFilter);
final PercolateQuery percolator = new PercolateQuery();
percolator.setVisibility(new Visibility().setFormalVisibility("U"));
percolator.setId(UUID.randomUUID().toString());
final String queryDoc = jsonBuilder().startObject().field("query", filteredQuery).endObject().string();
percolator.setQueryDocument(queryDoc);
// Action: Create and execute an OR match query on title
final IndexResponse percolateResponse = client.addPercolateQuery(percolator, fakeSecurity);
assertTrue(percolateResponse.isSuccess());
// Assert: There should be 3 matching documents
oneaaNavyYardDoc.setPercolate(new PercolateRequest());
oneaaColumbiaDoc.setPercolate(new PercolateRequest());
whiteHouseDoc.setPercolate(new PercolateRequest());
washingtonMonumentDoc.setPercolate(new PercolateRequest());
final List<PercolateQuery> matches = client.percolate(
Arrays.asList(
oneaaNavyYardDoc, oneaaColumbiaDoc, whiteHouseDoc, washingtonMonumentDoc), fakeSecurity);
assertEquals(3, matches.size());
pool.returnToPool(client);
}
示例6: checkStatisticsRecordExists
import org.elasticsearch.index.query.FilteredQueryBuilder; //导入依赖的package包/类
/**
* Check if some statistics record exists for specified conditions.
*
* @param type of record we are looking for
* @param conditions for lookup. Key is a name of field to filter over, Value is a value to filter for using term
* condition.
* @return true if at least one record matching conditions exits
*/
public boolean checkStatisticsRecordExists(StatsRecordType type, Map<String, Object> conditions) {
if (!statsConfiguration.enabled()) {
return false;
}
SearchRequestBuilder srb = new SearchRequestBuilder(client);
srb.setIndices(type.getSearchIndexName());
srb.setTypes(type.getSearchIndexType());
AndFilterBuilder fb = new AndFilterBuilder();
fb.add(new TermsFilterBuilder(FIELD_TYPE, type.getSearchIndexedValue()));
if (conditions != null) {
for (String fieldName : conditions.keySet()) {
fb.add(new TermsFilterBuilder(fieldName, conditions.get(fieldName)));
}
}
srb.setQuery(new FilteredQueryBuilder(QueryBuilders.matchAllQuery(), fb));
srb.addField("_id");
try {
SearchResponse searchResponse = srb.execute().actionGet();
return searchResponse.getHits().getTotalHits() > 0;
} catch (org.elasticsearch.indices.IndexMissingException e) {
return false;
}
}
示例7: applyCommonFilters
import org.elasticsearch.index.query.FilteredQueryBuilder; //导入依赖的package包/类
protected QueryBuilder applyCommonFilters(Map<String, FilterBuilder> searchFilters, QueryBuilder qb) {
if (!searchFilters.isEmpty()) {
return new FilteredQueryBuilder(qb, new AndFilterBuilder(searchFilters.values().toArray(
new FilterBuilder[searchFilters.size()])));
} else {
return qb;
}
}
示例8: checkStatisticsRecordExists
import org.elasticsearch.index.query.FilteredQueryBuilder; //导入依赖的package包/类
/**
* Check if some statistics record exists for specified conditions.
*
* @param type of record we are looking for
* @param conditions for lookup. Key is a name of field to filter over, Value is a value to filter for using term
* condition.
* @return true if at least one record matching conditions exits
*/
public boolean checkStatisticsRecordExists(StatsRecordType type, Map<String, Object> conditions) {
if (!statsConfiguration.enabled()) {
return false;
}
SearchRequestBuilder srb = new SearchRequestBuilder(client);
srb.setIndices(type.getSearchIndexName());
srb.setTypes(type.getSearchIndexType());
AndFilterBuilder fb = new AndFilterBuilder();
fb.add(new TermsFilterBuilder(FIELD_TYPE, type.getSearchIndexedValue()));
if (conditions != null) {
for (String fieldName : conditions.keySet()) {
fb.add(new TermsFilterBuilder(fieldName, conditions.get(fieldName)));
}
}
srb.setQuery(new FilteredQueryBuilder(QueryBuilders.matchAllQuery(), fb));
srb.addField("_id");
try {
SearchResponse searchResponse = srb.execute().actionGet();
return searchResponse.getHits().getTotalHits() > 0;
} catch (org.elasticsearch.indices.IndexMissingException e) {
return false;
}
}
示例9: applyContentLevelSecurityFilter
import org.elasticsearch.index.query.FilteredQueryBuilder; //导入依赖的package包/类
/**
* Apply "document level security" filtering to the query filter. See <a
* href="https://github.com/searchisko/searchisko/issues/143">issue #134</a>
*
* @param qb to apply additional filter to
* @return new query filter with applied security filtering
*/
protected QueryBuilder applyContentLevelSecurityFilter(QueryBuilder qb) {
FilterBuilder securityFilter = getContentLevelSecurityFilterInternal();
if (securityFilter == null) {
return qb;
} else {
return new FilteredQueryBuilder(qb, securityFilter);
}
}
示例10: queryInternal
import org.elasticsearch.index.query.FilteredQueryBuilder; //导入依赖的package包/类
private SettableFuture<SearchResponse> queryInternal(
AttributeQuerySet query,
Iterable<Publisher> publishers,
Selection selection
) {
SettableFuture<SearchResponse> response = SettableFuture.create();
EsQueryParser.EsQuery esQuery = esQueryParser.parse(query);
QueryBuilder queryBuilder = queryBuilderFactory.buildQuery(esQuery.getAttributeQuerySet());
/* matchAllFilter as a bool filter with less than 1 clause is invalid */
BoolFilterBuilder filterBuilder = FilterBuilders.boolFilter()
.must(FilterBuilders.matchAllFilter());
SearchRequestBuilder reqBuilder = esClient
.prepareSearch(index)
.setTypes(
EsContent.CHILD_ITEM,
EsContent.TOP_LEVEL_CONTAINER,
EsContent.TOP_LEVEL_ITEM
)
.addField(EsContent.CANONICAL_ID)
.addField(EsContent.ID)
.addField(EsContent.SOURCE)
.setPostFilter(FiltersBuilder.buildForPublishers(EsContent.SOURCE, publishers))
.setFrom(selection.getOffset())
.setSize(Objects.firstNonNull(selection.getLimit(), DEFAULT_LIMIT));
addOrdering(esQuery.getIndexQueryParams(), reqBuilder);
queryBuilder = addFuzzyQuery(esQuery.getIndexQueryParams(), queryBuilder, reqBuilder);
addBrandId(esQuery.getIndexQueryParams(), filterBuilder);
addSeriesId(esQuery.getIndexQueryParams(), filterBuilder);
addTopicFilter(esQuery.getIndexQueryParams(), filterBuilder);
addActionableFilter(esQuery.getIndexQueryParams(), filterBuilder);
reqBuilder.addSort(EsContent.ID, SortOrder.ASC);
FilteredQueryBuilder finalQuery = QueryBuilders.filteredQuery(queryBuilder, filterBuilder);
reqBuilder.setQuery(finalQuery);
log.debug(reqBuilder.internalBuilder().toString());
reqBuilder.execute(FutureSettingActionListener.setting(response));
return response;
}
示例11: testIndexingSingleInvoice
import org.elasticsearch.index.query.FilteredQueryBuilder; //导入依赖的package包/类
@Test
// @ElasticsearchIndex(
// indexName = ES_DEFAULT_INDEX_NAME_CAMUNDA_BPM,
// cleanAfter = true,
// mappings = @ElasticsearchMapping(typeName = ES_DEFAULT_TYPE_NAME_CAMUNDA_BPM, properties = {
// @Elasticsearch
// }))
public void testIndexingSingleInvoice() throws IOException {
HashMap<String,ProcessDataContainer> processesById = TestDataGenerator.startInvoiceProcess(processEngineRule.getProcessEngine(), 1);
String[] pids = processesById.keySet().toArray(new String[0]);
// elasticsearch //////////////////////////////
flushAndRefresh();
showMappings(ES_DEFAULT_INDEX_NAME_CAMUNDA_BPM);
FilteredQueryBuilder query = QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), FilterBuilders.termFilter("processInstanceId", pids[0]));
SearchRequestBuilder searchRequestBuilder = client.prepareSearch(ES_DEFAULT_INDEX_NAME_CAMUNDA_BPM)
.setQuery(query);
IoUtil.writeToFile(searchRequestBuilder.toString(), this.getClass().getSimpleName() + ".json", true);
SearchResponse searchResponse = searchRequestBuilder.get();
SearchHits hits = searchResponse.getHits();
assertEquals(1, hits.totalHits());
SearchHit hit = hits.getAt(0);
assertEquals(pids[0], hit.getId());
assertEquals(ES_DEFAULT_TYPE_NAME_CAMUNDA_BPM, hit.getType());
Map<String,Object> source = hit.getSource();
assertNotNull(source.get("startTime"));
assertNotNull(source.get("endTime"));
ArrayList variables = (ArrayList) source.get("variables");
assertEquals(5, variables.size());
ArrayList tasks = (ArrayList) source.get("tasks");
assertEquals(9, tasks.size());
ArrayList activities = (ArrayList) source.get("activities");
assertEquals(19, activities.size());
logger.info(searchResponse.toString());
// for (SearchHit searchHit : searchResponse.getHits()) {
// logger.info(searchHit.sourceAsString());
// }
showMappings(ES_DEFAULT_INDEX_NAME_CAMUNDA_BPM);
assertMappings(ES_DEFAULT_INDEX_NAME_CAMUNDA_BPM);
// TODO: write assertions for mapping
}
示例12: testIndexingSingleInvoice
import org.elasticsearch.index.query.FilteredQueryBuilder; //导入依赖的package包/类
@Test
public void testIndexingSingleInvoice() throws IOException {
HashMap<String,ProcessDataContainer> processesById = TestDataGenerator.startInvoiceProcess(processEngineRule.getProcessEngine(), 1);
String[] pids = processesById.keySet().toArray(new String[0]);
// elasticsearch //////////////////////////////
flushAndRefresh();
FilteredQueryBuilder query = QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), FilterBuilders.termFilter("processInstanceId", pids[0]));
SearchRequestBuilder searchRequestBuilder = client.prepareSearch(ES_DEFAULT_INDEX_NAME_CAMUNDA_BPM)
.setQuery(query);
IoUtil.writeToFile(searchRequestBuilder.toString(), this.getClass().getSimpleName() + ".json", true);
SearchResponse searchResponse = searchRequestBuilder.get();
SearchHits hits = searchResponse.getHits();
assertEquals(1, hits.totalHits());
SearchHit hit = hits.getAt(0);
assertEquals(pids[0], hit.getId());
assertEquals(ES_DEFAULT_TYPE_NAME_CAMUNDA_BPM, hit.getType());
Map<String,Object> source = hit.getSource();
assertNotNull(source.get("startTime"));
assertNotNull(source.get("endTime"));
ArrayList variables = (ArrayList) source.get("variables");
assertEquals(5, variables.size());
ArrayList tasks = (ArrayList) source.get("tasks");
assertEquals(9, tasks.size());
ArrayList activities = (ArrayList) source.get("activities");
assertEquals(19, activities.size());
logger.info(searchResponse.toString());
// for (SearchHit searchHit : searchResponse.getHits()) {
// logger.info(searchHit.sourceAsString());
// }
}
示例13: removeOldProjectEntriesFromIndex
import org.elasticsearch.index.query.FilteredQueryBuilder; //导入依赖的package包/类
public void removeOldProjectEntriesFromIndex(String projectId, List<String> supportedVersions) {
FilteredQueryBuilder builder = SaganQueryBuilders.matchUnsupportedProjectEntries(projectId, supportedVersions);
String query = SaganQueryBuilders.wrapQuery(builder.toString());
execute(new DeleteByQuery.Builder(query).build());
}