• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Operator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: urlParamsToQueryBuilder

import org.elasticsearch.index.query.Operator; //导入依赖的package包/类
public static QueryBuilder urlParamsToQueryBuilder(RestRequest request) {
    String queryString = request.param("q");
    if (queryString == null) {
        return null;
    }
    QueryStringQueryBuilder queryBuilder = QueryBuilders.queryStringQuery(queryString);
    queryBuilder.defaultField(request.param("df"));
    queryBuilder.analyzer(request.param("analyzer"));
    queryBuilder.analyzeWildcard(request.paramAsBoolean("analyze_wildcard", false));
    queryBuilder.lenient(request.paramAsBoolean("lenient", null));
    String defaultOperator = request.param("default_operator");
    if (defaultOperator != null) {
        queryBuilder.defaultOperator(Operator.fromString(defaultOperator));
    }
    return queryBuilder;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:RestActions.java


示例2: testMatchQueryWithStackedStems

import org.elasticsearch.index.query.Operator; //导入依赖的package包/类
public void testMatchQueryWithStackedStems() throws IOException {
    CreateIndexRequestBuilder builder = prepareCreate("test").setSettings(Settings.builder()
            .put(indexSettings())
            .put("index.analysis.analyzer.index.type", "custom")
            .put("index.analysis.analyzer.index.tokenizer", "standard")
            .put("index.analysis.analyzer.index.filter", "lowercase")
            .put("index.analysis.analyzer.search.type", "custom")
            .put("index.analysis.analyzer.search.tokenizer", "standard")
            .putArray("index.analysis.analyzer.search.filter", "lowercase", "keyword_repeat", "porter_stem", "unique_stem")
            .put("index.analysis.filter.unique_stem.type", "unique")
            .put("index.analysis.filter.unique_stem.only_on_same_position", true));
    assertAcked(builder.addMapping("test", "text", "type=text,analyzer=index,search_analyzer=search"));

    client().prepareIndex("test", "test", "1").setSource("text", "the fox runs across the street").get();
    refresh();
    SearchResponse searchResponse = client().prepareSearch("test").setQuery(matchQuery("text", "fox runs").operator(Operator.AND)).get();
    assertHitCount(searchResponse, 1);

    client().prepareIndex("test", "test", "2").setSource("text", "run fox run").get();
    refresh();
    searchResponse = client().prepareSearch("test").setQuery(matchQuery("text", "fox runs").operator(Operator.AND)).get();
    assertHitCount(searchResponse, 2);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:SearchQueryIT.java


示例3: testCustomWordDelimiterQueryString

import org.elasticsearch.index.query.Operator; //导入依赖的package包/类
public void testCustomWordDelimiterQueryString() {
    assertAcked(client().admin().indices().prepareCreate("test")
            .setSettings("analysis.analyzer.my_analyzer.type", "custom",
                    "analysis.analyzer.my_analyzer.tokenizer", "whitespace",
                    "analysis.analyzer.my_analyzer.filter", "custom_word_delimiter",
                    "analysis.filter.custom_word_delimiter.type", "word_delimiter",
                    "analysis.filter.custom_word_delimiter.generate_word_parts", "true",
                    "analysis.filter.custom_word_delimiter.generate_number_parts", "false",
                    "analysis.filter.custom_word_delimiter.catenate_numbers", "true",
                    "analysis.filter.custom_word_delimiter.catenate_words", "false",
                    "analysis.filter.custom_word_delimiter.split_on_case_change", "false",
                    "analysis.filter.custom_word_delimiter.split_on_numerics", "false",
                    "analysis.filter.custom_word_delimiter.stem_english_possessive", "false")
            .addMapping("type1", "field1", "type=text,analyzer=my_analyzer", "field2", "type=text,analyzer=my_analyzer"));

    client().prepareIndex("test", "type1", "1").setSource("field1", "foo bar baz", "field2", "not needed").get();
    refresh();

    SearchResponse response = client()
            .prepareSearch("test")
            .setQuery(
                    queryStringQuery("foo.baz").useDisMax(false).defaultOperator(Operator.AND)
                            .field("field1").field("field2")).get();
    assertHitCount(response, 1L);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:SearchQueryIT.java


示例4: testExplicitAllFieldsRequested

import org.elasticsearch.index.query.Operator; //导入依赖的package包/类
public void testExplicitAllFieldsRequested() throws Exception {
    String indexBody = copyToStringFromClasspath("/org/elasticsearch/search/query/all-query-index-with-all.json");
    prepareCreate("test2").setSource(indexBody, XContentType.JSON).get();
    ensureGreen("test2");

    List<IndexRequestBuilder> reqs = new ArrayList<>();
    reqs.add(client().prepareIndex("test2", "doc", "1").setSource("f1", "foo", "f2", "eggplant"));
    indexRandom(true, false, reqs);

    SearchResponse resp = client().prepareSearch("test2").setQuery(
            queryStringQuery("foo eggplent").defaultOperator(Operator.AND)).get();
    assertHitCount(resp, 0L);

    resp = client().prepareSearch("test2").setQuery(
            queryStringQuery("foo eggplent").defaultOperator(Operator.AND).useAllFields(true)).get();
    assertHits(resp.getHits(), "1");
    assertHitCount(resp, 1L);

    Exception e = expectThrows(Exception.class, () ->
            client().prepareSearch("test2").setQuery(
                    queryStringQuery("blah").field("f1").useAllFields(true)).get());
    assertThat(ExceptionsHelper.detailedMessage(e),
            containsString("cannot use [all_fields] parameter in conjunction with [default_field] or [fields]"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:QueryStringIT.java


示例5: testDefaults

import org.elasticsearch.index.query.Operator; //导入依赖的package包/类
public void testDefaults() throws ExecutionException, InterruptedException {
    MatchQuery.Type type = randomBoolean() ? MatchQueryBuilder.DEFAULT_TYPE : MatchQuery.Type.BOOLEAN;
    SearchResponse searchResponse = client().prepareSearch("test")
            .setQuery(randomizeType(multiMatchQuery("marvel hero captain america", "full_name", "first_name", "last_name", "category")
                    .operator(Operator.OR))).get();
    Set<String> topNIds = Sets.newHashSet("theone", "theother");
    for (int i = 0; i < searchResponse.getHits().getHits().length; i++) {
        topNIds.remove(searchResponse.getHits().getAt(i).getId());
        // very likely that we hit a random doc that has the same score so orders are random since
        // the doc id is the tie-breaker
    }
    assertThat(topNIds, empty());
    assertThat(searchResponse.getHits().getHits()[0].getScore(), greaterThan(searchResponse.getHits().getHits()[1].getScore()));

    searchResponse = client().prepareSearch("test")
            .setQuery(randomizeType(multiMatchQuery("marvel hero captain america", "full_name", "first_name", "last_name", "category")
                    .operator(Operator.OR).useDisMax(false).type(type))).get();
    assertFirstHit(searchResponse, anyOf(hasId("theone"), hasId("theother")));
    assertThat(searchResponse.getHits().getHits()[0].getScore(), greaterThan(searchResponse.getHits().getHits()[1].getScore()));

    searchResponse = client().prepareSearch("test")
            .setQuery(randomizeType(multiMatchQuery("marvel hero", "full_name", "first_name", "last_name", "category")
                    .operator(Operator.OR).type(type))).get();
    assertFirstHit(searchResponse, hasId("theother"));


    searchResponse = client().prepareSearch("test")
            .setQuery(randomizeType(multiMatchQuery("captain america", "full_name", "first_name", "last_name", "category")
                    .operator(Operator.AND).type(type))).get();
    assertHitCount(searchResponse, 1L);
    assertFirstHit(searchResponse, hasId("theone"));

    searchResponse = client().prepareSearch("test")
            .setQuery(randomizeType(multiMatchQuery("captain america", "full_name", "first_name", "last_name", "category")
                    .operator(Operator.AND).type(type))).get();
    assertHitCount(searchResponse, 1L);
    assertFirstHit(searchResponse, hasId("theone"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:39,代码来源:MultiMatchQueryIT.java


示例6: testPhraseType

import org.elasticsearch.index.query.Operator; //导入依赖的package包/类
public void testPhraseType() {
    SearchResponse searchResponse = client().prepareSearch("test")
            .setQuery(randomizeType(multiMatchQuery("Man the Ultimate", "full_name_phrase", "first_name_phrase", "last_name_phrase", "category_phrase")
                    .operator(Operator.OR).type(MatchQuery.Type.PHRASE))).get();
    assertFirstHit(searchResponse, hasId("ultimate2"));
    assertHitCount(searchResponse, 1L);

    searchResponse = client().prepareSearch("test")
            .setQuery(randomizeType(multiMatchQuery("Captain", "full_name_phrase", "first_name_phrase", "last_name_phrase", "category_phrase")
                    .operator(Operator.OR).type(MatchQuery.Type.PHRASE))).get();
    assertThat(searchResponse.getHits().getTotalHits(), greaterThan(1L));

    searchResponse = client().prepareSearch("test")
            .setQuery(randomizeType(multiMatchQuery("the Ul", "full_name_phrase", "first_name_phrase", "last_name_phrase", "category_phrase")
                    .operator(Operator.OR).type(MatchQuery.Type.PHRASE_PREFIX))).get();
    assertSearchHits(searchResponse, "ultimate2", "ultimate1");
    assertHitCount(searchResponse, 2L);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:MultiMatchQueryIT.java


示例7: randomCommonTermsQuery

import org.elasticsearch.index.query.Operator; //导入依赖的package包/类
private static QueryBuilder randomCommonTermsQuery(List<String> fields, int numDocs) {
    int numTerms = randomInt(numDocs);

    QueryBuilder q = QueryBuilders.commonTermsQuery(randomField(fields), randomQueryString(numTerms));
    if (randomBoolean()) {
        ((CommonTermsQueryBuilder)q).boost(randomFloat());
    }

    if (randomBoolean()) {
        ((CommonTermsQueryBuilder)q).cutoffFrequency(randomFloat());
    }

    if (randomBoolean()) {
        ((CommonTermsQueryBuilder)q).highFreqMinimumShouldMatch(Integer.toString(randomInt(numTerms)))
                .highFreqOperator(randomBoolean() ? Operator.AND : Operator.OR);
    }

    if (randomBoolean()) {
        ((CommonTermsQueryBuilder)q).lowFreqMinimumShouldMatch(Integer.toString(randomInt(numTerms)))
                .lowFreqOperator(randomBoolean() ? Operator.AND : Operator.OR);
    }

    return q;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:RandomQueryGenerator.java


示例8: testSimpleMultiTermAnd

import org.elasticsearch.index.query.Operator; //导入依赖的package包/类
public void testSimpleMultiTermAnd() throws ExecutionException, InterruptedException {
    indexRandom(true, false, getDocs());

    // first search using regular synonym field using phrase
    SearchResponse searchResponse = client().prepareSearch(INDEX).setQuery(QueryBuilders.matchQuery("field", "say what the fudge")
        .operator(Operator.AND).analyzer("lower_syns")).get();

    // Old synonyms work fine in that case, but it is coincidental
    assertHitCount(searchResponse, 1L);
    assertSearchHits(searchResponse, "1");

    // same query using graph should find correct result
    searchResponse = client().prepareSearch(INDEX).setQuery(QueryBuilders.matchQuery("field", "say what the fudge")
        .operator(Operator.AND).analyzer("lower_graphsyns")).get();

    assertHitCount(searchResponse, 1L);
    assertSearchHits(searchResponse, "1");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:MatchQueryIT.java


示例9: testMinShouldMatch

import org.elasticsearch.index.query.Operator; //导入依赖的package包/类
public void testMinShouldMatch() throws ExecutionException, InterruptedException {
    indexRandom(true, false, getDocs());

    // no min should match
    SearchResponse searchResponse = client().prepareSearch(INDEX).setQuery(QueryBuilders.matchQuery("field", "three what the fudge foo")
        .operator(Operator.OR).analyzer("lower_graphsyns")).get();

    assertHitCount(searchResponse, 6L);
    assertSearchHits(searchResponse, "1", "2", "3", "4", "5", "6");

    // same query, with min_should_match of 2
    searchResponse = client().prepareSearch(INDEX).setQuery(QueryBuilders.matchQuery("field", "three what the fudge foo")
        .operator(Operator.OR).analyzer("lower_graphsyns").minimumShouldMatch("80%")).get();

    // three wtf foo = 2 terms, match #1
    // three wtf bar baz = 3 terms, match #6
    // three what the fudge foo = 4 terms, no match
    // three what the fudge bar baz = 4 terms, match #2
    assertHitCount(searchResponse, 3L);
    assertSearchHits(searchResponse, "1", "2", "6");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:MatchQueryIT.java


示例10: find

import org.elasticsearch.index.query.Operator; //导入依赖的package包/类
public String find() {
  try {
    final SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
    searchSourceBuilder.sort("_score");
    searchSourceBuilder.sort("_uid");

    final String queryText = "*";
    final SimpleQueryStringBuilder simpleQueryStringBuilder =
        new SimpleQueryStringBuilder(queryText);
    simpleQueryStringBuilder.defaultOperator(Operator.AND);
    searchSourceBuilder.query(simpleQueryStringBuilder);
    searchSourceBuilder.size(500);

    //LOGGER.info("Elasticsearch query: {}", searchSourceBuilder.toString());

    final SearchRequest searchRequest = new SearchRequest();
    searchRequest.indices("tweets");
    searchRequest.types("tweet");
    searchRequest.source(searchSourceBuilder);
    final SearchResponse searchResponse = restHighLevelClient.search(searchRequest);
    return searchResponse.toString();
  } catch (IOException e) {
    e.printStackTrace();
    return e.getMessage();
  }
}
 
开发者ID:jeqo,项目名称:talk-observing-distributed-systems,代码行数:27,代码来源:ElasticsearchTweetRepository.java


示例11: match

import org.elasticsearch.index.query.Operator; //导入依赖的package包/类
/**
     * simple match
     * use whitespace analyzer
     * @param field
     * @param phrase already stemmed
     * @param operator and /or
     * @return
     */
    public SearchResponse match(String field, String phrase, Operator operator){

        SearchResponse response = client.prepareSearch(indexName).setSize(this.numDocs).
                setTrackScores(false).
                setFetchSource(false).setExplain(false).setFetchSource(false).
                setQuery(QueryBuilders.matchQuery(field, phrase).operator(operator)
                        .analyzer("whitespace")).
                execute().actionGet();
        return response;

//        debug
//        XContentBuilder builder = XContentFactory.jsonBuilder();
//        builder.startObject();
//        System.out.println(response.toXContent(builder, ToXContent.EMPTY_PARAMS));
//        builder.endObject();
//        System.out.println(builder.string());
    }
 
开发者ID:cheng-li,项目名称:pyramid,代码行数:26,代码来源:ESIndex.java


示例12: simpleQueryBuilder

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


示例13: testMatchQueryWithSynonyms

import org.elasticsearch.index.query.Operator; //导入依赖的package包/类
public void testMatchQueryWithSynonyms() throws IOException {
    CreateIndexRequestBuilder builder = prepareCreate("test").setSettings(Settings.builder()
            .put(indexSettings())
            .put("index.analysis.analyzer.index.type", "custom")
            .put("index.analysis.analyzer.index.tokenizer", "standard")
            .put("index.analysis.analyzer.index.filter", "lowercase")
            .put("index.analysis.analyzer.search.type", "custom")
            .put("index.analysis.analyzer.search.tokenizer", "standard")
            .putArray("index.analysis.analyzer.search.filter", "lowercase", "synonym")
            .put("index.analysis.filter.synonym.type", "synonym")
            .putArray("index.analysis.filter.synonym.synonyms", "fast, quick"));
    assertAcked(builder.addMapping("test", "text", "type=text,analyzer=index,search_analyzer=search"));

    client().prepareIndex("test", "test", "1").setSource("text", "quick brown fox").get();
    refresh();
    SearchResponse searchResponse = client().prepareSearch("test").setQuery(matchQuery("text", "quick").operator(Operator.AND)).get();
    assertHitCount(searchResponse, 1);
    searchResponse = client().prepareSearch("test").setQuery(matchQuery("text", "quick brown").operator(Operator.AND)).get();
    assertHitCount(searchResponse, 1);
    searchResponse = client().prepareSearch("test").setQuery(matchQuery("text", "fast").operator(Operator.AND)).get();
    assertHitCount(searchResponse, 1);

    client().prepareIndex("test", "test", "2").setSource("text", "fast brown fox").get();
    refresh();
    searchResponse = client().prepareSearch("test").setQuery(matchQuery("text", "quick").operator(Operator.AND)).get();
    assertHitCount(searchResponse, 2);
    searchResponse = client().prepareSearch("test").setQuery(matchQuery("text", "quick brown").operator(Operator.AND)).get();
    assertHitCount(searchResponse, 2);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:SearchQueryIT.java


示例14: testQueryStringWithSynonyms

import org.elasticsearch.index.query.Operator; //导入依赖的package包/类
public void testQueryStringWithSynonyms() throws IOException {
    CreateIndexRequestBuilder builder = prepareCreate("test").setSettings(Settings.builder()
            .put(indexSettings())
            .put("index.analysis.analyzer.index.type", "custom")
            .put("index.analysis.analyzer.index.tokenizer", "standard")
            .put("index.analysis.analyzer.index.filter", "lowercase")
            .put("index.analysis.analyzer.search.type", "custom")
            .put("index.analysis.analyzer.search.tokenizer", "standard")
            .putArray("index.analysis.analyzer.search.filter", "lowercase", "synonym")
            .put("index.analysis.filter.synonym.type", "synonym")
            .putArray("index.analysis.filter.synonym.synonyms", "fast, quick"));
    assertAcked(builder.addMapping("test", "text", "type=text,analyzer=index,search_analyzer=search"));

    client().prepareIndex("test", "test", "1").setSource("text", "quick brown fox").get();
    refresh();

    SearchResponse searchResponse = client().prepareSearch("test").setQuery(queryStringQuery("quick").defaultField("text").defaultOperator(Operator.AND)).get();
    assertHitCount(searchResponse, 1);
    searchResponse = client().prepareSearch("test").setQuery(queryStringQuery("quick brown").defaultField("text").defaultOperator(Operator.AND)).get();
    assertHitCount(searchResponse, 1);
    searchResponse = client().prepareSearch().setQuery(queryStringQuery("fast").defaultField("text").defaultOperator(Operator.AND)).get();
    assertHitCount(searchResponse, 1);

    client().prepareIndex("test", "test", "2").setSource("text", "fast brown fox").get();
    refresh();

    searchResponse = client().prepareSearch("test").setQuery(queryStringQuery("quick").defaultField("text").defaultOperator(Operator.AND)).get();
    assertHitCount(searchResponse, 2);
    searchResponse = client().prepareSearch("test").setQuery(queryStringQuery("quick brown").defaultField("text").defaultOperator(Operator.AND)).get();
    assertHitCount(searchResponse, 2);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:32,代码来源:SearchQueryIT.java


示例15: testExplicitAllFieldsRequested

import org.elasticsearch.index.query.Operator; //导入依赖的package包/类
public void testExplicitAllFieldsRequested() throws Exception {
    String indexBody = copyToStringFromClasspath("/org/elasticsearch/search/query/all-query-index-with-all.json");
    prepareCreate("test")
            .setSource(indexBody, XContentType.JSON)
            // .setSettings(Settings.builder().put("index.version.created", Version.V_5_0_0.id)).get();
            .get();
    ensureGreen("test");

    List<IndexRequestBuilder> reqs = new ArrayList<>();
    reqs.add(client().prepareIndex("test", "doc", "1").setSource("f1", "foo", "f2", "eggplant"));
    indexRandom(true, false, reqs);

    SearchResponse resp = client().prepareSearch("test").setQuery(
            simpleQueryStringQuery("foo eggplent").defaultOperator(Operator.AND)).get();
    assertHitCount(resp, 0L);

    resp = client().prepareSearch("test").setQuery(
            simpleQueryStringQuery("foo eggplent").defaultOperator(Operator.AND).useAllFields(true)).get();
    assertHits(resp.getHits(), "1");
    assertHitCount(resp, 1L);

    Exception e = expectThrows(Exception.class, () ->
            client().prepareSearch("test").setQuery(
                    simpleQueryStringQuery("blah").field("f1").useAllFields(true)).get());
    assertThat(ExceptionsHelper.detailedMessage(e),
            containsString("cannot use [all_fields] parameter in conjunction with [fields]"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:SimpleQueryStringIT.java


示例16: testSynonyms

import org.elasticsearch.index.query.Operator; //导入依赖的package包/类
public void testSynonyms() throws IOException {
    Builder builder = Settings.builder()
        .put(indexSettings())
        .put("index.analysis.analyzer.synonym.tokenizer", "whitespace")
        .putArray("index.analysis.analyzer.synonym.filter", "synonym", "lowercase")
        .put("index.analysis.filter.synonym.type", "synonym")
        .putArray("index.analysis.filter.synonym.synonyms", "fast,quick");

    assertAcked(prepareCreate("test").setSettings(builder.build())
        .addMapping("type1", "field1",
            "type=text,term_vector=with_positions_offsets,search_analyzer=synonym," +
                "analyzer=english,index_options=offsets"));
    ensureGreen();

    client().prepareIndex("test", "type1", "0").setSource(
        "field1", "The quick brown fox jumps over the lazy dog").get();
    refresh();
    for (String highlighterType : ALL_TYPES) {
        logger.info("--> highlighting (type=" + highlighterType + ") and searching on field1");
        SearchSourceBuilder source = searchSource()
            .query(matchQuery("field1", "quick brown fox").operator(Operator.AND))
            .highlighter(
                highlight()
                    .field("field1")
                    .order("score")
                    .preTags("<x>")
                    .postTags("</x>")
                    .highlighterType(highlighterType));
        SearchResponse searchResponse = client().search(searchRequest("test").source(source)).actionGet();
        assertHighlight(searchResponse, 0, "field1", 0, 1,
            equalTo("The <x>quick</x> <x>brown</x> <x>fox</x> jumps over the lazy dog"));

        source = searchSource()
            .query(matchQuery("field1", "fast brown fox").operator(Operator.AND))
            .highlighter(highlight().field("field1").order("score").preTags("<x>").postTags("</x>"));
        searchResponse = client().search(searchRequest("test").source(source)).actionGet();
        assertHighlight(searchResponse, 0, "field1", 0, 1,
            equalTo("The <x>quick</x> <x>brown</x> <x>fox</x> jumps over the lazy dog"));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:41,代码来源:HighlighterSearchIT.java


示例17: testCommonTerms

import org.elasticsearch.index.query.Operator; //导入依赖的package包/类
public void testCommonTerms() throws ExecutionException, InterruptedException {
    String route = "commonTermsTest";
    List<IndexRequestBuilder> builders = getDocs();
    for (IndexRequestBuilder indexRequet : builders) {
        // route all docs to same shard for this test
        indexRequet.setRouting(route);
    }
    indexRandom(true, false, builders);

    // do a search with no cutoff frequency to show which docs should match
    SearchResponse searchResponse = client().prepareSearch(INDEX)
        .setRouting(route)
        .setQuery(QueryBuilders.matchQuery("field", "bar three happened")
            .operator(Operator.OR)).get();

    assertHitCount(searchResponse, 4L);
    assertSearchHits(searchResponse, "1", "2", "5", "6");

    // do same search with cutoff and see less documents match
    // in this case, essentially everything but "happened" gets excluded
    searchResponse = client().prepareSearch(INDEX)
        .setRouting(route)
        .setQuery(QueryBuilders.matchQuery("field", "bar three happened")
            .operator(Operator.OR).cutoffFrequency(1f)).get();

    assertHitCount(searchResponse, 1L);
    assertSearchHits(searchResponse, "1");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:29,代码来源:MatchQueryIT.java


示例18: addQuery

import org.elasticsearch.index.query.Operator; //导入依赖的package包/类
private void addQuery(BoolQueryBuilder boolQuery, boolean positive, String query, String modifier) {
    if (Strings.isNullOrEmpty(query)) {
        return;
    }
    QueryStringQueryBuilder builder = QueryBuilders.queryStringQuery(query)
            .field("title." + modifier)
            .field("text." + modifier)
            .defaultOperator(Operator.AND);
    if (positive) {
        boolQuery.must(builder);
    } else {
        boolQuery.mustNot(builder);
    }
}
 
开发者ID:tokenmill,项目名称:crawling-framework,代码行数:15,代码来源:EsDocumentOperations.java


示例19: getByDomain

import org.elasticsearch.index.query.Operator; //导入依赖的package包/类
/**
 * 根据domain获取结果
 *
 * @param domain 网站域名
 * @param size   每页数量
 * @param page   页码
 * @return
 */
public List<SpiderInfo> getByDomain(String domain, int size, int page) {
    SearchRequestBuilder searchRequestBuilder = client.prepareSearch(INDEX_NAME)
            .setTypes(TYPE_NAME)
            .setQuery(QueryBuilders.matchQuery("domain", domain).operator(Operator.AND))
            .setSize(size).setFrom(size * (page - 1));
    SearchResponse response = searchRequestBuilder.execute().actionGet();
    return warpHits2List(response.getHits());
}
 
开发者ID:bruceq,项目名称:Gather-Platform,代码行数:17,代码来源:SpiderInfoDAO.java


示例20: testPercolateQueryWithNestedDocuments

import org.elasticsearch.index.query.Operator; //导入依赖的package包/类
public void testPercolateQueryWithNestedDocuments() throws Exception {
    XContentBuilder mapping = XContentFactory.jsonBuilder();
    mapping.startObject().startObject("properties").startObject("companyname").field("type", "text").endObject()
            .startObject("employee").field("type", "nested").startObject("properties")
            .startObject("name").field("type", "text").endObject().endObject().endObject().endObject()
            .endObject();
    createIndex("test", client().admin().indices().prepareCreate("test")
            .addMapping("employee", mapping)
            .addMapping("queries", "query", "type=percolator")
    );
    client().prepareIndex("test", "queries", "q1").setSource(jsonBuilder().startObject()
            .field("query", QueryBuilders.nestedQuery("employee",
                    QueryBuilders.matchQuery("employee.name", "virginia potts").operator(Operator.AND), ScoreMode.Avg)
            ).endObject())
            .get();
    // this query should never match as it doesn't use nested query:
    client().prepareIndex("test", "queries", "q2").setSource(jsonBuilder().startObject()
            .field("query", QueryBuilders.matchQuery("employee.name", "virginia")).endObject())
            .get();
    client().admin().indices().prepareRefresh().get();

    SearchResponse response = client().prepareSearch()
            .setQuery(new PercolateQueryBuilder("query", "employee",
                    XContentFactory.jsonBuilder()
                        .startObject().field("companyname", "stark")
                            .startArray("employee")
                                .startObject().field("name", "virginia potts").endObject()
                                .startObject().field("name", "tony stark").endObject()
                            .endArray()
                        .endObject().bytes(), XContentType.JSON))
            .addSort("_doc", SortOrder.ASC)
            .get();
    assertHitCount(response, 1);
    assertThat(response.getHits().getAt(0).getId(), equalTo("q1"));

    response = client().prepareSearch()
            .setQuery(new PercolateQueryBuilder("query", "employee",
                    XContentFactory.jsonBuilder()
                        .startObject().field("companyname", "notstark")
                            .startArray("employee")
                                .startObject().field("name", "virginia stark").endObject()
                                .startObject().field("name", "tony stark").endObject()
                            .endArray()
                        .endObject().bytes(), XContentType.JSON))
            .addSort("_doc", SortOrder.ASC)
            .get();
    assertHitCount(response, 0);

    response = client().prepareSearch()
            .setQuery(new PercolateQueryBuilder("query", "employee",
                    XContentFactory.jsonBuilder().startObject().field("companyname", "notstark").endObject().bytes(),
                XContentType.JSON))
            .addSort("_doc", SortOrder.ASC)
            .get();
    assertHitCount(response, 0);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:57,代码来源:PercolatorQuerySearchIT.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ICODecoder类代码示例发布时间:2022-05-22
下一篇:
Java MBeanFactory类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap