本文整理汇总了Java中org.elasticsearch.index.query.IdsQueryBuilder类的典型用法代码示例。如果您正苦于以下问题:Java IdsQueryBuilder类的具体用法?Java IdsQueryBuilder怎么用?Java IdsQueryBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IdsQueryBuilder类属于org.elasticsearch.index.query包,在下文中一共展示了IdsQueryBuilder类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: toMultiSearchRequest
import org.elasticsearch.index.query.IdsQueryBuilder; //导入依赖的package包/类
protected MultiSearchRequest toMultiSearchRequest(final MultiGetRequest multiGetRequest) {
final MultiSearchRequest msearch = new MultiSearchRequest();
msearch.copyContextFrom(multiGetRequest);
for (final Iterator<Item> iterator = multiGetRequest.iterator(); iterator.hasNext();) {
final Item item = iterator.next();
final SearchRequest st = new SearchRequest();
st.routing(item.routing());
st.indices(item.indices());
st.types(item.type());
st.preference(multiGetRequest.preference());
st.source(SearchSourceBuilder.searchSource().query(new IdsQueryBuilder(item.type()).addIds(item.id())));
msearch.add(st);
}
return msearch;
}
开发者ID:petalmd,项目名称:armor,代码行数:21,代码来源:AbstractActionFilter.java
示例2: matchPhrase
import org.elasticsearch.index.query.IdsQueryBuilder; //导入依赖的package包/类
/**
* phrase query
* use whitespace analyzer in the query
* @param field
* @param phrase already stemmed
* @param ids
* @param slop
* @return
*/
public SearchResponse matchPhrase(String field, String phrase,
String[] ids, int slop) {
IdsQueryBuilder idsFilterBuilder = new IdsQueryBuilder(documentType);
idsFilterBuilder.addIds(ids);
SearchResponse response = client.prepareSearch(indexName).setSize(ids.length)
.setTrackScores(false)
.setFetchSource(false).setExplain(false).setFetchSource(false).
setQuery(QueryBuilders.boolQuery().must(QueryBuilders.matchPhraseQuery(field, phrase)
.slop(slop).analyzer("whitespace")).filter(idsFilterBuilder))
.execute().actionGet();
// debug
// XContentBuilder builder = XContentFactory.jsonBuilder();
// builder.startObject();
// System.out.println(response.toXContent(builder, ToXContent.EMPTY_PARAMS));
// builder.endObject();
// System.out.println(builder.string());
return response;
}
开发者ID:cheng-li,项目名称:pyramid,代码行数:32,代码来源:ESIndex.java
示例3: count
import org.elasticsearch.index.query.IdsQueryBuilder; //导入依赖的package包/类
public long count(Ngram ngram, String[] ids){
String field = ngram.getField();
int slop = ngram.getSlop();
boolean inOrder = ngram.isInOrder();
SpanNearQueryBuilder queryBuilder = QueryBuilders.spanNearQuery(new SpanTermQueryBuilder(field, ngram.getTerms()[0]), slop);
for (int i = 1; i < ngram.getTerms().length; i++){
queryBuilder.addClause(new SpanTermQueryBuilder(field, ngram.getTerms()[1]));
}
queryBuilder.inOrder(inOrder);
IdsQueryBuilder idsFilterBuilder = new IdsQueryBuilder(documentType);
idsFilterBuilder.addIds(ids);
long hits = client.prepareSearch(this.indexName).setQuery(queryBuilder)
.execute().actionGet().getHits().getTotalHits();
return hits;
}
开发者ID:cheng-li,项目名称:pyramid,代码行数:19,代码来源:ESIndex.java
示例4: randomIDsQuery
import org.elasticsearch.index.query.IdsQueryBuilder; //导入依赖的package包/类
private static QueryBuilder randomIDsQuery() {
QueryBuilder q = QueryBuilders.idsQuery();
int numIDs = randomInt(100);
for (int i = 0; i < numIDs; i++) {
((IdsQueryBuilder)q).addIds(String.valueOf(randomInt()));
}
if (randomBoolean()) {
((IdsQueryBuilder)q).boost(randomFloat());
}
return q;
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:15,代码来源:RandomQueryGenerator.java
示例5: randomNestedFilter
import org.elasticsearch.index.query.IdsQueryBuilder; //导入依赖的package包/类
protected static QueryBuilder randomNestedFilter() {
int id = randomIntBetween(0, 2);
switch(id) {
case 0: return (new MatchAllQueryBuilder()).boost(randomFloat());
case 1: return (new IdsQueryBuilder()).boost(randomFloat());
case 2: return (new TermQueryBuilder(
randomAsciiOfLengthBetween(1, 10),
randomDouble()).boost(randomFloat()));
default: throw new IllegalStateException("Only three query builders supported for testing sort");
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:AbstractSortTestCase.java
示例6: testHasParentInnerQueryType
import org.elasticsearch.index.query.IdsQueryBuilder; //导入依赖的package包/类
public void testHasParentInnerQueryType() {
assertAcked(prepareCreate("test").addMapping("parent-type").addMapping("child-type", "_parent", "type=parent-type"));
client().prepareIndex("test", "child-type", "child-id").setParent("parent-id").setSource("{}", XContentType.JSON).get();
client().prepareIndex("test", "parent-type", "parent-id").setSource("{}", XContentType.JSON).get();
refresh();
//make sure that when we explicitly set a type, the inner query is executed in the context of the parent type instead
SearchResponse searchResponse = client().prepareSearch("test").setTypes("child-type").setQuery(
QueryBuilders.hasParentQuery("parent-type", new IdsQueryBuilder().addIds("parent-id"), false)).get();
assertSearchHits(searchResponse, "child-id");
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:ChildQuerySearchIT.java
示例7: testHasChildInnerQueryType
import org.elasticsearch.index.query.IdsQueryBuilder; //导入依赖的package包/类
public void testHasChildInnerQueryType() {
assertAcked(prepareCreate("test").addMapping("parent-type").addMapping("child-type", "_parent", "type=parent-type"));
client().prepareIndex("test", "child-type", "child-id").setParent("parent-id").setSource("{}", XContentType.JSON).get();
client().prepareIndex("test", "parent-type", "parent-id").setSource("{}", XContentType.JSON).get();
refresh();
//make sure that when we explicitly set a type, the inner query is executed in the context of the child type instead
SearchResponse searchResponse = client().prepareSearch("test").setTypes("parent-type").setQuery(
QueryBuilders.hasChildQuery("child-type", new IdsQueryBuilder().addIds("child-id"), ScoreMode.None)).get();
assertSearchHits(searchResponse, "parent-id");
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:ChildQuerySearchIT.java
示例8: findProductById
import org.elasticsearch.index.query.IdsQueryBuilder; //导入依赖的package包/类
@Override
public Map<String, Object> findProductById(Id productId) {
Client client = ElasticSearch.CLIENT.get();
ApplicationContext appCtx = app.context();
Merchant merchant = appCtx.getMerchant();
Store store = appCtx.getStore();
IdsQueryBuilder qb = QueryBuilders.idsQuery(SEARCH_TYPE_PRODUCT);
qb.addIds(productId.str());
SearchRequestBuilder searchRequestBuilder = client
.prepareSearch(elasticsearchIndexHelper.indexName(merchant.getId(), store.getId(), Product.class))
.setTypes(Annotations.getIndexedCollectionName(Product.class))
.setSearchType(SearchType.QUERY_THEN_FETCH).setQuery(qb).setExplain(false);
SearchResponse response = searchRequestBuilder.execute().actionGet();
SearchHits hits = response.getHits();
Map<String, Object> productData = null;
if (hits.getTotalHits() > 0) {
SearchHit searchHit = hits.getAt(0);
if (searchHit != null)
productData = searchHit.getSource();
}
return productData;
}
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:32,代码来源:DefaultProductListService.java
示例9: toSearchRequest
import org.elasticsearch.index.query.IdsQueryBuilder; //导入依赖的package包/类
protected SearchRequest toSearchRequest(final RestRequest request) {
final SearchRequest searchRequest = new SearchRequest();
searchRequest.routing(request.param("routing"));
searchRequest.copyContextFrom(request);
searchRequest.preference(request.param("preference"));
searchRequest.indices(request.param("index"));
searchRequest.types(request.param("type"));
searchRequest.source(SearchSourceBuilder.searchSource().query(
new IdsQueryBuilder(request.param("type")).addIds(request.param("id"))));
return searchRequest;
}
开发者ID:petalmd,项目名称:armor,代码行数:14,代码来源:AbstractACRestFilter.java
示例10: toMultiSearchRequest
import org.elasticsearch.index.query.IdsQueryBuilder; //导入依赖的package包/类
protected MultiSearchRequest toMultiSearchRequest(final RestRequest request) throws Exception {
final MultiGetRequest multiGetRequest = new MultiGetRequest();
multiGetRequest.refresh(request.paramAsBoolean("refresh", multiGetRequest.refresh()));
multiGetRequest.preference(request.param("preference"));
multiGetRequest.realtime(request.paramAsBoolean("realtime", null));
multiGetRequest.ignoreErrorsOnGeneratedFields(request.paramAsBoolean("ignore_errors_on_generated_fields", false));
String[] sFields = null;
final String sField = request.param("fields");
if (sField != null) {
sFields = Strings.splitStringByCommaToArray(sField);
}
final FetchSourceContext defaultFetchSource = FetchSourceContext.parseFromRestRequest(request);
multiGetRequest.add(request.param("index"), request.param("type"), sFields, defaultFetchSource, request.param("routing"),
RestActions.getRestContent(request),
settings.getAsBoolean(AbstractACRestFilter.REST_ACTION_MULTI_ALLOW_EXPLICIT_INDEX, true));
final MultiSearchRequest msearch = new MultiSearchRequest();
msearch.copyContextFrom(request);
for (final Iterator<Item> iterator = multiGetRequest.iterator(); iterator.hasNext();) {
final Item item = iterator.next();
final SearchRequest st = new SearchRequest();
st.routing(item.routing());
st.indices(item.indices());
st.types(item.type());
st.preference(request.param("preference"));
st.source(SearchSourceBuilder.searchSource().query(new IdsQueryBuilder(item.type()).addIds(item.id())));
msearch.add(st);
}
return msearch;
}
开发者ID:petalmd,项目名称:armor,代码行数:38,代码来源:AbstractACRestFilter.java
示例11: toSearchRequest
import org.elasticsearch.index.query.IdsQueryBuilder; //导入依赖的package包/类
protected SearchRequest toSearchRequest(final GetRequest request) {
final SearchRequest searchRequest = new SearchRequest();
searchRequest.routing(request.routing());
searchRequest.copyContextFrom(request);
searchRequest.preference(request.preference());
searchRequest.indices(request.indices());
searchRequest.types(request.type());
searchRequest.source(SearchSourceBuilder.searchSource().query(new IdsQueryBuilder(request.type()).addIds(request.id())));
return searchRequest;
}
开发者ID:petalmd,项目名称:armor,代码行数:13,代码来源:AbstractActionFilter.java
示例12: searchByGuids
import org.elasticsearch.index.query.IdsQueryBuilder; //导入依赖的package包/类
/**
* Return the search hit based on the UUID and sensor type.
* A callback can be specified to transform the hit into a type T.
* If more than one hit happens, the first one will be returned.
*/
<T> List<T> searchByGuids(Collection<String> guids, Collection<String> sensorTypes,
Function<SearchHit, Optional<T>> callback) {
if(guids == null || guids.isEmpty()) {
return Collections.EMPTY_LIST;
}
QueryBuilder query = null;
IdsQueryBuilder idsQuery = null;
if (sensorTypes != null) {
String[] types = sensorTypes.stream().map(sensorType -> sensorType + "_doc").toArray(String[]::new);
idsQuery = QueryBuilders.idsQuery(types);
} else {
idsQuery = QueryBuilders.idsQuery();
}
for(String guid : guids) {
query = idsQuery.addIds(guid);
}
SearchRequestBuilder request = client.prepareSearch()
.setQuery(query)
.setSize(guids.size())
;
org.elasticsearch.action.search.SearchResponse response = request.get();
SearchHits hits = response.getHits();
List<T> results = new ArrayList<>();
for (SearchHit hit : hits) {
Optional<T> result = callback.apply(hit);
if (result.isPresent()) {
results.add(result.get());
}
}
return results;
}
开发者ID:apache,项目名称:metron,代码行数:39,代码来源:ElasticsearchDao.java
示例13: match
import org.elasticsearch.index.query.IdsQueryBuilder; //导入依赖的package包/类
/**
* simple match
* use whitespace analyzer
* @param field
* @param phrase already stemmed
* @param ids
* @param operator
* @return
*/
public SearchResponse match(String field, String phrase, String[] ids,
Operator operator){
IdsQueryBuilder idsFilterBuilder = new IdsQueryBuilder(documentType);
idsFilterBuilder.addIds(ids);
SearchResponse response = client.prepareSearch(indexName).setSize(ids.length).
setTrackScores(false).
setFetchSource(false).setExplain(false).setFetchSource(false).
setQuery(QueryBuilders.boolQuery()
.should(QueryBuilders.matchQuery(field, phrase)
.operator(operator).analyzer("whitespace"))
.must(idsFilterBuilder))
.execute().actionGet();
return response;
}
开发者ID:cheng-li,项目名称:pyramid,代码行数:24,代码来源:ESIndex.java
示例14: deleteByIds
import org.elasticsearch.index.query.IdsQueryBuilder; //导入依赖的package包/类
public static void deleteByIds(
Client client, String index, String type, Set<String> ids, EzSecurityToken token,
VisibilityFilterConfig filterConfig) throws TException {
final SearchRequestBuilder idRequest = createIdSearch(client, index, type, ids, token, filterConfig);
idRequest.setNoFields();
final SearchResponse idResponse = idRequest.get();
final IdsQueryBuilder deleteQuery = QueryBuilders.idsQuery(type);
for (final SearchHit hit : idResponse.getHits().getHits()) {
deleteQuery.addIds(hit.getId());
}
client.prepareDeleteByQuery(index).setQuery(deleteQuery).get();
refreshIndex(client, index);
}
开发者ID:ezbake,项目名称:ezelastic,代码行数:16,代码来源:ElasticUtils.java
示例15: buildIdsQuery
import org.elasticsearch.index.query.IdsQueryBuilder; //导入依赖的package包/类
public QueryBuilder buildIdsQuery(Collection<String> ids) {
IdsQueryBuilder queryBuilder = QueryBuilders.idsQuery(getIndexType());
queryBuilder.ids().addAll(ids);
return queryBuilder;
}
开发者ID:Lambda-3,项目名称:Stargraph,代码行数:6,代码来源:ElasticClient.java
示例16: registerQueryParsers
import org.elasticsearch.index.query.IdsQueryBuilder; //导入依赖的package包/类
private void registerQueryParsers(List<SearchPlugin> plugins) {
registerQuery(new QuerySpec<>(MatchQueryBuilder.NAME, MatchQueryBuilder::new, MatchQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(MatchPhraseQueryBuilder.NAME, MatchPhraseQueryBuilder::new, MatchPhraseQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(MatchPhrasePrefixQueryBuilder.NAME, MatchPhrasePrefixQueryBuilder::new,
MatchPhrasePrefixQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(MultiMatchQueryBuilder.NAME, MultiMatchQueryBuilder::new, MultiMatchQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(NestedQueryBuilder.NAME, NestedQueryBuilder::new, NestedQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(HasChildQueryBuilder.NAME, HasChildQueryBuilder::new, HasChildQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(HasParentQueryBuilder.NAME, HasParentQueryBuilder::new, HasParentQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(DisMaxQueryBuilder.NAME, DisMaxQueryBuilder::new, DisMaxQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(IdsQueryBuilder.NAME, IdsQueryBuilder::new, IdsQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(MatchAllQueryBuilder.NAME, MatchAllQueryBuilder::new, MatchAllQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(QueryStringQueryBuilder.NAME, QueryStringQueryBuilder::new, QueryStringQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(BoostingQueryBuilder.NAME, BoostingQueryBuilder::new, BoostingQueryBuilder::fromXContent));
BooleanQuery.setMaxClauseCount(INDICES_MAX_CLAUSE_COUNT_SETTING.get(settings));
registerQuery(new QuerySpec<>(BoolQueryBuilder.NAME, BoolQueryBuilder::new, BoolQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(TermQueryBuilder.NAME, TermQueryBuilder::new, TermQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(TermsQueryBuilder.NAME, TermsQueryBuilder::new, TermsQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(FuzzyQueryBuilder.NAME, FuzzyQueryBuilder::new, FuzzyQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(RegexpQueryBuilder.NAME, RegexpQueryBuilder::new, RegexpQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(RangeQueryBuilder.NAME, RangeQueryBuilder::new, RangeQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(PrefixQueryBuilder.NAME, PrefixQueryBuilder::new, PrefixQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(WildcardQueryBuilder.NAME, WildcardQueryBuilder::new, WildcardQueryBuilder::fromXContent));
registerQuery(
new QuerySpec<>(ConstantScoreQueryBuilder.NAME, ConstantScoreQueryBuilder::new, ConstantScoreQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(SpanTermQueryBuilder.NAME, SpanTermQueryBuilder::new, SpanTermQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(SpanNotQueryBuilder.NAME, SpanNotQueryBuilder::new, SpanNotQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(SpanWithinQueryBuilder.NAME, SpanWithinQueryBuilder::new, SpanWithinQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(SpanContainingQueryBuilder.NAME, SpanContainingQueryBuilder::new,
SpanContainingQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(FieldMaskingSpanQueryBuilder.NAME, FieldMaskingSpanQueryBuilder::new,
FieldMaskingSpanQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(SpanFirstQueryBuilder.NAME, SpanFirstQueryBuilder::new, SpanFirstQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(SpanNearQueryBuilder.NAME, SpanNearQueryBuilder::new, SpanNearQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(SpanOrQueryBuilder.NAME, SpanOrQueryBuilder::new, SpanOrQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(MoreLikeThisQueryBuilder.NAME, MoreLikeThisQueryBuilder::new,
MoreLikeThisQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(WrapperQueryBuilder.NAME, WrapperQueryBuilder::new, WrapperQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(CommonTermsQueryBuilder.NAME, CommonTermsQueryBuilder::new, CommonTermsQueryBuilder::fromXContent));
registerQuery(
new QuerySpec<>(SpanMultiTermQueryBuilder.NAME, SpanMultiTermQueryBuilder::new, SpanMultiTermQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(FunctionScoreQueryBuilder.NAME, FunctionScoreQueryBuilder::new,
FunctionScoreQueryBuilder::fromXContent));
registerQuery(
new QuerySpec<>(SimpleQueryStringBuilder.NAME, SimpleQueryStringBuilder::new, SimpleQueryStringBuilder::fromXContent));
registerQuery(new QuerySpec<>(TypeQueryBuilder.NAME, TypeQueryBuilder::new, TypeQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(ScriptQueryBuilder.NAME, ScriptQueryBuilder::new, ScriptQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(GeoDistanceQueryBuilder.NAME, GeoDistanceQueryBuilder::new, GeoDistanceQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(GeoBoundingBoxQueryBuilder.NAME, GeoBoundingBoxQueryBuilder::new,
GeoBoundingBoxQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(GeoPolygonQueryBuilder.NAME, GeoPolygonQueryBuilder::new, GeoPolygonQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(ExistsQueryBuilder.NAME, ExistsQueryBuilder::new, ExistsQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(MatchNoneQueryBuilder.NAME, MatchNoneQueryBuilder::new, MatchNoneQueryBuilder::fromXContent));
registerQuery(new QuerySpec<>(ParentIdQueryBuilder.NAME, ParentIdQueryBuilder::new, ParentIdQueryBuilder::fromXContent));
if (ShapesAvailability.JTS_AVAILABLE && ShapesAvailability.SPATIAL4J_AVAILABLE) {
registerQuery(new QuerySpec<>(GeoShapeQueryBuilder.NAME, GeoShapeQueryBuilder::new, GeoShapeQueryBuilder::fromXContent));
}
registerFromPlugin(plugins, SearchPlugin::getQueries, this::registerQuery);
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:62,代码来源:SearchModule.java
示例17: testSecureRandomScript1
import org.elasticsearch.index.query.IdsQueryBuilder; //导入依赖的package包/类
@Test
public void testSecureRandomScript1() throws Exception {
// Create a new index
final String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties")
.startObject("name").field("type", "string").endObject().startObject("number").field("type", "integer").endObject()
.endObject().endObject().endObject().string();
assertAcked(prepareCreate("test").addMapping("type", mapping));
assertAcked(prepareCreate("test1").addMapping("type", mapping));
index("test", "type", "1doc", "{\"a\":1}");
index("test", "type", "2doc", "{\"a\":2}");
index("test", "type", "3doc", "{\"a\":3}");
index("test", "type", "4doc", "{\"a\":4}");
index("test", "type", "5doc", "{\"a\":5,\"b\":3}");
for (int i = 0; i < 30; i++) {
client().prepareIndex("test", "type").setSource("{\"dummy\":0}").get();
}
final int bulkCount = 4000;
final List<IndexRequestBuilder> indexBuilders = new ArrayList<IndexRequestBuilder>();
for (int i = 0; i < bulkCount; i++) {
indexBuilders.add(client().prepareIndex("test", "type", Integer.toString(i)).setSource(
XContentFactory.jsonBuilder().startObject().field("name", "rec " + i).field("number", i).endObject()));
}
indexRandom(true, false, indexBuilders);
client().prepareUpdate("test", "type", "5doc").setScript("ctx._source.b++", ScriptType.INLINE).get();
client().prepareIndex("test", "type", "4doc").setSource("{\"a\":44}").get();
client().prepareDelete("test", "type", "4doc").get();
client().prepareDeleteByQuery("test", "test1").setQuery(new IdsQueryBuilder("type").addIds("1doc", "2doc")).get();
refresh();
SearchResponse searchResponse = client().prepareSearch("test").setQuery(matchAllQuery()).execute().actionGet();
assertNoFailures(searchResponse);
assertHitCountWithMsg("testsearch", searchResponse, 32 + bulkCount);
int flushCount = 0;
do {
final FlushResponse res = client().admin().cluster().execute(FlushAction.INSTANCE, new FlushRequest()).actionGet();
flushCount = res.getCount();
refresh();
logger.info("Flushed {} msgs", flushCount);
} while (flushCount > 0);
searchResponse = client().prepareSearch("audit").setQuery(matchAllQuery()).execute().actionGet();
assertNoFailures(searchResponse);
System.out.println("Audit search result " + searchResponse.getHits().totalHits());
//assertHitCountWithMsg("auditsearch",searchResponse, flushCount+bulkCount);
}
开发者ID:salyh,项目名称:elasticsearch-sample-plugin-audit,代码行数:59,代码来源:AuditTest.java
示例18: spanNot
import org.elasticsearch.index.query.IdsQueryBuilder; //导入依赖的package包/类
public SearchResponse spanNot(SpanNotNgram ngram, String[] ids){
Ngram include = ngram.getInclude();
String field1 = include.getField();
int slop1 = include.getSlop();
boolean inOrder1 = include.isInOrder();
SpanNearQueryBuilder queryBuilder1 = QueryBuilders.spanNearQuery(new SpanTermQueryBuilder(field1, include.getTerms()[0]), slop1);
for (int i = 1; i < include.getTerms().length; i++){
queryBuilder1.addClause(new SpanTermQueryBuilder(field1, include.getTerms()[i]));
}
queryBuilder1.inOrder(inOrder1);
Ngram exclude = ngram.getExclude();
String field2 = exclude.getField();
int slop2 = exclude.getSlop();
boolean inOrder2 = exclude.isInOrder();
SpanNearQueryBuilder queryBuilder2 = QueryBuilders.spanNearQuery(new SpanTermQueryBuilder(field2, exclude.getTerms()[0]), slop2);
for (int i = 1; i < exclude.getTerms().length; i++){
queryBuilder2.addClause(new SpanTermQueryBuilder(field2, exclude.getTerms()[i]));
}
queryBuilder2.inOrder(inOrder2);
int pre = ngram.getPre();
int post = ngram.getPost();
SpanNotQueryBuilder spanNotQueryBuilder = new SpanNotQueryBuilder(queryBuilder1, queryBuilder2);
//todo upgrade to 1.5
// .pre(pre).post(post);
IdsQueryBuilder idsFilterBuilder = new IdsQueryBuilder(documentType);
idsFilterBuilder.addIds(ids);
SearchResponse response = client.prepareSearch(indexName).setSize(ids.length).
setTrackScores(false).
setFetchSource(false).setExplain(false).setFetchSource(false).
setQuery(QueryBuilders.boolQuery()
.must(idsFilterBuilder)
.should(spanNotQueryBuilder))
.execute().actionGet();
return response;
}
开发者ID:cheng-li,项目名称:pyramid,代码行数:44,代码来源:ESIndex.java
示例19: buildIdQuery
import org.elasticsearch.index.query.IdsQueryBuilder; //导入依赖的package包/类
/**
* Creates query for specific id of type.
*
* @param type
* type name
* @param ids
* list of ids
* @return query for id
*/
protected QueryBuilder buildIdQuery(String type, List<String> ids) {
return new IdsQueryBuilder().types(type).addIds(ids.toArray(new String[1]));
}
开发者ID:Hevelian,项目名称:hevelian-olastic,代码行数:13,代码来源:ESQueryBuilder.java
注:本文中的org.elasticsearch.index.query.IdsQueryBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论