当前位置: 首页>>代码示例>>Java>>正文


Java MatchAllQueryBuilder类代码示例

本文整理汇总了Java中org.elasticsearch.index.query.MatchAllQueryBuilder的典型用法代码示例。如果您正苦于以下问题:Java MatchAllQueryBuilder类的具体用法?Java MatchAllQueryBuilder怎么用?Java MatchAllQueryBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MatchAllQueryBuilder类属于org.elasticsearch.index.query包,在下文中一共展示了MatchAllQueryBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testUnsupportedQueries

import org.elasticsearch.index.query.MatchAllQueryBuilder; //导入依赖的package包/类
public void testUnsupportedQueries() {
    RangeQueryBuilder rangeQuery1 = new RangeQueryBuilder("field").from("2016-01-01||/D").to("2017-01-01||/D");
    RangeQueryBuilder rangeQuery2 = new RangeQueryBuilder("field").from("2016-01-01||/D").to("now");
    PercolatorFieldMapper.verifyQuery(rangeQuery1);
    expectThrows(IllegalArgumentException.class, () -> PercolatorFieldMapper.verifyQuery(rangeQuery2));
    PercolatorFieldMapper.verifyQuery(new BoolQueryBuilder().must(rangeQuery1));
    expectThrows(IllegalArgumentException.class, () ->
            PercolatorFieldMapper.verifyQuery(new BoolQueryBuilder().must(rangeQuery2)));
    PercolatorFieldMapper.verifyQuery(new ConstantScoreQueryBuilder((rangeQuery1)));
    expectThrows(IllegalArgumentException.class, () ->
            PercolatorFieldMapper.verifyQuery(new ConstantScoreQueryBuilder(rangeQuery2)));
    PercolatorFieldMapper.verifyQuery(new BoostingQueryBuilder(rangeQuery1, new MatchAllQueryBuilder()));
    expectThrows(IllegalArgumentException.class, () ->
            PercolatorFieldMapper.verifyQuery(new BoostingQueryBuilder(rangeQuery2, new MatchAllQueryBuilder())));
    PercolatorFieldMapper.verifyQuery(new FunctionScoreQueryBuilder(rangeQuery1, new RandomScoreFunctionBuilder()));
    expectThrows(IllegalArgumentException.class, () ->
            PercolatorFieldMapper.verifyQuery(new FunctionScoreQueryBuilder(rangeQuery2, new RandomScoreFunctionBuilder())));

    HasChildQueryBuilder hasChildQuery = new HasChildQueryBuilder("_type", new MatchAllQueryBuilder(), ScoreMode.None);
    expectThrows(IllegalArgumentException.class, () -> PercolatorFieldMapper.verifyQuery(hasChildQuery));
    expectThrows(IllegalArgumentException.class, () -> PercolatorFieldMapper.verifyQuery(new BoolQueryBuilder().must(hasChildQuery)));

    HasParentQueryBuilder hasParentQuery = new HasParentQueryBuilder("_type", new MatchAllQueryBuilder(), false);
    expectThrows(IllegalArgumentException.class, () -> PercolatorFieldMapper.verifyQuery(hasParentQuery));
    expectThrows(IllegalArgumentException.class, () -> PercolatorFieldMapper.verifyQuery(new BoolQueryBuilder().must(hasParentQuery)));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:PercolatorFieldMapperTests.java

示例2: randomRescoreBuilder

import org.elasticsearch.index.query.MatchAllQueryBuilder; //导入依赖的package包/类
/**
 * create random shape that is put under test
 */
public static QueryRescorerBuilder randomRescoreBuilder() {
    QueryBuilder queryBuilder = new MatchAllQueryBuilder().boost(randomFloat())
            .queryName(randomAsciiOfLength(20));
    org.elasticsearch.search.rescore.QueryRescorerBuilder rescorer = new
            org.elasticsearch.search.rescore.QueryRescorerBuilder(queryBuilder);
    if (randomBoolean()) {
        rescorer.setQueryWeight(randomFloat());
    }
    if (randomBoolean()) {
        rescorer.setRescoreQueryWeight(randomFloat());
    }
    if (randomBoolean()) {
        rescorer.setScoreMode(randomFrom(QueryRescoreMode.values()));
    }
    if (randomBoolean()) {
        rescorer.windowSize(randomIntBetween(0, 100));
    }
    return rescorer;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:QueryRescoreBuilderTests.java

示例3: shouldSaveTwice

import org.elasticsearch.index.query.MatchAllQueryBuilder; //导入依赖的package包/类
@Test
public void shouldSaveTwice() {
  final ImmutableList.Builder<Person> builder = ImmutableList.builder();
  for(int i=0; i< ElasticSearchRepository.SCROLL_SIZE * 2;i++) {
    builder.add(PERSON);
  }
  final List<Person> persons = builder.build();

  final List<Person> saved = repository.saveAll(persons);
  assertEquals(persons.size(), saved.size());

  final List<Person> found = repository.search(new MatchAllQueryBuilder());
  assertEquals(persons.size(), found.size());

  repository.deleteAll(saved);
}
 
开发者ID:jloisel,项目名称:elastic-crud,代码行数:17,代码来源:RepositoryIntegrationTest.java

示例4: should_generate_id_when_not_specified

import org.elasticsearch.index.query.MatchAllQueryBuilder; //导入依赖的package包/类
@Test
public void should_generate_id_when_not_specified() throws IOException, ExecutionException, InterruptedException {
    BytesReference source = source().bytes();
    IndexRequest request = Requests.indexRequest().index(THE_INDEX)
            .type(THE_TYPE)
            .source(source.toBytes())
            .refresh(true);
    Map<String, Object> expected = SourceLookup.sourceAsMap(source);

    httpClient.index(request).get();

    MatchAllQueryBuilder query = QueryBuilders.matchAllQuery();
    SearchResponse searchResponse = new SearchRequestBuilder(transportClient).setQuery(query).setIndices(THE_INDEX).execute().actionGet();
    Assertions.assertThat(searchResponse.getHits().getTotalHits()).isEqualTo(1);
    Assertions.assertThat(searchResponse.getHits().getHits()[0].sourceAsMap()).hasSameSizeAs(expected);
    compareMap(expected, searchResponse.getHits().getHits()[0].sourceAsMap());
}
 
开发者ID:obourgain,项目名称:elasticsearch-http,代码行数:18,代码来源:IndexActionHandlerTest.java

示例5: simpleQueryBuilder

import org.elasticsearch.index.query.MatchAllQueryBuilder; //导入依赖的package包/类
public static QueryBuilder simpleQueryBuilder(String q) {
    if (q.equals("yacyall")) return new MatchAllQueryBuilder();
    final MultiMatchQueryBuilder qb = QueryBuilders
            .multiMatchQuery(q)
            .operator(Operator.AND)
            .zeroTermsQuery(ZeroTermsQuery.ALL);
    QUERY_DEFAULT_FIELDS.forEach((mapping, boost) -> qb.field(mapping.getSolrFieldName(), boost));
    return qb;
}
 
开发者ID:yacy,项目名称:yacy_grid_mcp,代码行数:10,代码来源:YaCyQuery.java

示例6: testMustRewrite

import org.elasticsearch.index.query.MatchAllQueryBuilder; //导入依赖的package包/类
@Override
public void testMustRewrite() throws IOException {
    String query = "{ \"match_all\" : {}}";
    QueryBuilder builder = new TemplateQueryBuilder(new Script(ScriptType.INLINE, "mockscript", query,
        Collections.singletonMap(Script.CONTENT_TYPE_OPTION, XContentType.JSON.mediaType()), Collections.emptyMap()));
    try {
        builder.toQuery(createShardContext());
        fail();
    } catch (UnsupportedOperationException ex) {
        assertEquals("this query must be rewritten first", ex.getMessage());
    }
    assertEquals(new MatchAllQueryBuilder(), builder.rewrite(createShardContext()));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:TemplateQueryBuilderTests.java

示例7: testRewriteWithInnerName

import org.elasticsearch.index.query.MatchAllQueryBuilder; //导入依赖的package包/类
public void testRewriteWithInnerName() throws IOException {
    final String query = "{ \"match_all\" : {\"_name\" : \"foobar\"}}";
    QueryBuilder builder = new TemplateQueryBuilder(new Script(ScriptType.INLINE, "mockscript", query,
        Collections.singletonMap(Script.CONTENT_TYPE_OPTION, XContentType.JSON.mediaType()), Collections.emptyMap()));
    assertEquals(new MatchAllQueryBuilder().queryName("foobar"), builder.rewrite(createShardContext()));

    builder = new TemplateQueryBuilder(new Script(ScriptType.INLINE, "mockscript", query, Collections.singletonMap(
        Script.CONTENT_TYPE_OPTION, XContentType.JSON.mediaType()), Collections.emptyMap())).queryName("outer");
    assertEquals(new BoolQueryBuilder().must(new MatchAllQueryBuilder().queryName("foobar")).queryName("outer"),
        builder.rewrite(createShardContext()));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:TemplateQueryBuilderTests.java

示例8: testMinScoreFunctionScoreBasic

import org.elasticsearch.index.query.MatchAllQueryBuilder; //导入依赖的package包/类
public void testMinScoreFunctionScoreBasic() throws IOException {
    index(INDEX, TYPE, jsonBuilder().startObject().field("num", 2).endObject());
    refresh();
    float score = randomFloat();
    float minScore = randomFloat();

    index(INDEX, TYPE, jsonBuilder().startObject()
            .field("num", 2)
            .field("random_score", score) // Pass the random score as a document field so that it can be extracted in the script
            .endObject());
    refresh();
    ensureYellow();

    Script script = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['random_score']", Collections.emptyMap());
    SearchResponse searchResponse = client().search(
            searchRequest().source(searchSource().query(functionScoreQuery(scriptFunction(script)).setMinScore(minScore)))
    ).actionGet();
    if (score < minScore) {
        assertThat(searchResponse.getHits().getTotalHits(), is(0L));
    } else {
        assertThat(searchResponse.getHits().getTotalHits(), is(1L));
    }

    searchResponse = client().search(
            searchRequest().source(searchSource().query(functionScoreQuery(new MatchAllQueryBuilder(), new FilterFunctionBuilder[] {
                            new FilterFunctionBuilder(scriptFunction(script)),
                            new FilterFunctionBuilder(scriptFunction(script))
                    }).scoreMode(FiltersFunctionScoreQuery.ScoreMode.AVG).setMinScore(minScore)))
            ).actionGet();
    if (score < minScore) {
        assertThat(searchResponse.getHits().getTotalHits(), is(0L));
    } else {
        assertThat(searchResponse.getHits().getTotalHits(), is(1L));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:36,代码来源:FunctionScoreIT.java

示例9: testMinScoreFunctionScoreManyDocsAndRandomMinScore

import org.elasticsearch.index.query.MatchAllQueryBuilder; //导入依赖的package包/类
public void testMinScoreFunctionScoreManyDocsAndRandomMinScore() throws IOException, ExecutionException, InterruptedException {
    List<IndexRequestBuilder> docs = new ArrayList<>();
    int numDocs = randomIntBetween(1, 100);
    int scoreOffset = randomIntBetween(-2 * numDocs, 2 * numDocs);
    int minScore = randomIntBetween(-2 * numDocs, 2 * numDocs);
    for (int i = 0; i < numDocs; i++) {
        docs.add(client().prepareIndex(INDEX, TYPE, Integer.toString(i)).setSource("num", i + scoreOffset));
    }
    indexRandom(true, docs);
    Script script = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "return (doc['num'].value)", Collections.emptyMap());
    int numMatchingDocs = numDocs + scoreOffset - minScore;
    if (numMatchingDocs < 0) {
        numMatchingDocs = 0;
    }
    if (numMatchingDocs > numDocs) {
        numMatchingDocs = numDocs;
    }

    SearchResponse searchResponse = client().search(
            searchRequest().source(searchSource().query(functionScoreQuery(scriptFunction(script))
                    .setMinScore(minScore)).size(numDocs))).actionGet();
    assertMinScoreSearchResponses(numDocs, searchResponse, numMatchingDocs);

    searchResponse = client().search(
            searchRequest().source(searchSource().query(functionScoreQuery(new MatchAllQueryBuilder(), new FilterFunctionBuilder[] {
                    new FilterFunctionBuilder(scriptFunction(script)),
                    new FilterFunctionBuilder(scriptFunction(script))
            }).scoreMode(FiltersFunctionScoreQuery.ScoreMode.AVG).setMinScore(minScore)).size(numDocs))).actionGet();
    assertMinScoreSearchResponses(numDocs, searchResponse, numMatchingDocs);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:31,代码来源:FunctionScoreIT.java

示例10: randomNestedFilter

import org.elasticsearch.index.query.MatchAllQueryBuilder; //导入依赖的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

示例11: testHighlightersIgnoreParentChild

import org.elasticsearch.index.query.MatchAllQueryBuilder; //导入依赖的package包/类
public void testHighlightersIgnoreParentChild() {
    assertAcked(prepareCreate("test")
            .addMapping("parent-type", "searchText", "type=text,term_vector=with_positions_offsets,index_options=offsets")
            .addMapping("child-type", "_parent", "type=parent-type", "searchText",
                    "type=text,term_vector=with_positions_offsets,index_options=offsets"));
    client().prepareIndex("test", "parent-type", "parent-id").setSource("searchText", "quick brown fox").get();
    client().prepareIndex("test", "child-type", "child-id").setParent("parent-id").setSource("searchText", "quick brown fox").get();
    refresh();

    String[] highlightTypes = new String[] {"plain", "fvh", "postings"};
    for (String highlightType : highlightTypes) {
        logger.info("Testing with highlight type [{}]", highlightType);
        SearchResponse searchResponse = client().prepareSearch("test")
                .setQuery(new BoolQueryBuilder()
                        .must(new MatchQueryBuilder("searchText", "fox"))
                        .must(new HasChildQueryBuilder("child-type", new MatchAllQueryBuilder(), ScoreMode.None))
                )
                .highlighter(new HighlightBuilder().field(new HighlightBuilder.Field("searchText").highlighterType(highlightType)))
                .get();
        assertHitCount(searchResponse, 1);
        assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("parent-id"));
        HighlightField highlightField = searchResponse.getHits().getAt(0).getHighlightFields().get("searchText");
        assertThat(highlightField.getFragments()[0].string(), equalTo("quick brown <em>fox</em>"));

        searchResponse = client().prepareSearch("test")
                .setQuery(new BoolQueryBuilder()
                        .must(new MatchQueryBuilder("searchText", "fox"))
                        .must(new HasParentQueryBuilder("parent-type", new MatchAllQueryBuilder(), false))
                )
                .highlighter(new HighlightBuilder().field(new HighlightBuilder.Field("searchText").highlighterType(highlightType)))
                .get();
        assertHitCount(searchResponse, 1);
        assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("child-id"));
        highlightField = searchResponse.getHits().getAt(0).getHighlightFields().get("searchText");
        assertThat(highlightField.getFragments()[0].string(), equalTo("quick brown <em>fox</em>"));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:38,代码来源:ChildQuerySearchIT.java

示例12: mergeAggWithSelect

import org.elasticsearch.index.query.MatchAllQueryBuilder; //导入依赖的package包/类
/**
 * Merges a top level aggregation query with an inner select
 * @param result
 * @param subQuery
 * @return
 * @throws SQLException 
 */
private ParseResult mergeAggWithSelect(ParseResult top, ParseResult nested) throws SQLException {
	if(nested.getRequestScore()) throw new SQLException("Unable to request a _score on an aggregation");
	int limit = top.getLimit();
	List<OrderBy> sorts = top.getSorts();
	boolean useCache = top.getUseCache() || nested.getUseCache();
	
	QueryBuilder query = top.getQuery();
	if(query instanceof MatchAllQueryBuilder) query = nested.getQuery();
	else if(!(nested.getQuery() instanceof MatchAllQueryBuilder)) query = QueryBuilders.boolQuery().must(top.getQuery()).must(nested.getQuery());
	
	AbstractAggregationBuilder agg = top.getAggregation();
	IComparison having = top.getHaving();
	Heading head = new Heading();
	if(nested.getHeading().hasAllCols()){
		head = top.getHeading();
	}else{
		for(Column col : top.getHeading().columns()){
			if(col.hasCalculation()){
				translateCalculation(col.getCalculation(), nested.getHeading());
				head.add(new Column(col.getColumn(), col.getOp()).setAlias(col.getAlias())
						.setCalculation(col.getCalculation()).setSqlType(Types.FLOAT));
			}else{
				Column col2 = nested.getHeading().getColumnByNameAndOp(col.getColumn(), Operation.NONE);
				if(col2 == null) col2 = nested.getHeading().getColumnByLabel(col.getAlias());
				if(col2 == null && col.getOp() == Operation.COUNT){
					head.add(col);
					continue;
				}else if(col2 == null) throw new SQLException("Unable to determine column '"+col.getLabel()+"' within nested query");
				String alias = (col.getAlias() == null ? col.getColumn() : col.getAlias());
				head.add(new Column(col2.getColumn(), col.getOp()).setAlias(alias).setVisible(col.isVisible())
						.setSqlType(col2.getSqlType()));
			}
		}
	}
	head.buildIndex();
	return new ParseResult(head, nested.getSources(), query, agg, having, sorts, limit, useCache, false);
}
 
开发者ID:Anchormen,项目名称:sql4es,代码行数:45,代码来源:QueryParser.java

示例13: KeyIterator

import org.elasticsearch.index.query.MatchAllQueryBuilder; //导入依赖的package包/类
public KeyIterator(ElasticsearchIndex index) {
	this.index = index;
	MatchAllQueryBuilder query = QueryBuilders.matchAllQuery();
	scrollResp = index.getClient().prepareSearch(index.getIndex()).setTypes(index.getType())
			.addFields(new String[] {}).setSearchType(SearchType.SCAN)
			.setScroll(new TimeValue(ElasticsearchIndex.SCROLLTIMEOUT)).setQuery(query)
			.setSize(ElasticsearchIndex.SCROLLSIZE).execute().actionGet();
	scrollResp = index.getClient().prepareSearchScroll(scrollResp.getScrollId())
			.setScroll(new TimeValue(ElasticsearchIndex.SCROLLTIMEOUT)).execute().actionGet();
	iterator = scrollResp.getHits().iterator();
}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:12,代码来源:ElasticsearchIndex.java

示例14: download

import org.elasticsearch.index.query.MatchAllQueryBuilder; //导入依赖的package包/类
public void download() throws IOException {
	String fileName = index + "_" + time + ".json";
	String fullFileName = outputPath + "/" + fileName;

	System.out.println("Begin downloading index: " + this.index + " to "
			+ fileName);
	FileOutputStream fos = new FileOutputStream(fullFileName);
	BufferedOutputStream bos = new BufferedOutputStream(fos);
	try {
		SearchResponse scrollResp = client.prepareSearch(index)
				.setSearchType(SearchType.SCAN)
				.setScroll(new TimeValue(SCROLL_TIMEOUT))
				.setQuery(new MatchAllQueryBuilder()).setSize(SCROLL_SIZE)
				.execute().actionGet();
		// Scroll until no hits are returned
		while (true) {
			for (SearchHit hit : scrollResp.getHits().getHits()) {
				bos.write(hit.source());
				bos.write("\n".getBytes());
			}
			System.out.println(Thread.currentThread().getName()
					+ ": flushing... ");
			bos.flush();
			scrollResp = client
					.prepareSearchScroll(scrollResp.getScrollId())
					.setScroll(new TimeValue(SCROLL_TIMEOUT)).execute()
					.actionGet();
			// Break condition: No hits are returned
			if (scrollResp.getHits().getHits().length == 0) {
				break;
			}
		}
	} finally {
		bos.close();
	}
	System.out.println(Thread.currentThread().getName() + ": done");
}
 
开发者ID:vchau,项目名称:es-downloader,代码行数:38,代码来源:IndexDownloader.java

示例15: truncateIndex

import org.elasticsearch.index.query.MatchAllQueryBuilder; //导入依赖的package包/类
public IndexDeleteByQueryResponse truncateIndex() throws InterruptedException, ExecutionException {
    try (Client client = getClient()) {
        QueryBuilder queryBuilder = new MatchAllQueryBuilder();
        ListenableActionFuture<DeleteByQueryResponse> response = client.prepareDeleteByQuery(INDEX_NAME)
                .setTypes(DOCUMENT_TYPE).setQuery(queryBuilder).execute();
        DeleteByQueryResponse deleteByQueryResponse = response.get();
        IndexDeleteByQueryResponse indexResult = deleteByQueryResponse.getIndex(INDEX_NAME);
        return indexResult;
    }
}
 
开发者ID:datacleaner,项目名称:extension_elasticsearch,代码行数:11,代码来源:ElasticSearchTestServer.java


注:本文中的org.elasticsearch.index.query.MatchAllQueryBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。