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


Java Operator类代码示例

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


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


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