當前位置: 首頁>>代碼示例>>Java>>正文


Java QueryBuilder.toXContent方法代碼示例

本文整理匯總了Java中org.elasticsearch.index.query.QueryBuilder.toXContent方法的典型用法代碼示例。如果您正苦於以下問題:Java QueryBuilder.toXContent方法的具體用法?Java QueryBuilder.toXContent怎麽用?Java QueryBuilder.toXContent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.elasticsearch.index.query.QueryBuilder的用法示例。


在下文中一共展示了QueryBuilder.toXContent方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: filter

import org.elasticsearch.index.query.QueryBuilder; //導入方法依賴的package包/類
/**
 * Associates a filter to the alias
 */
public Alias filter(QueryBuilder filterBuilder) {
    if (filterBuilder == null) {
        this.filter = null;
        return this;
    }
    try {
        XContentBuilder builder = XContentFactory.jsonBuilder();
        filterBuilder.toXContent(builder, ToXContent.EMPTY_PARAMS);
        builder.close();
        this.filter = builder.string();
        return this;
    } catch (IOException e) {
        throw new ElasticsearchGenerationException("Failed to build json for alias request", e);
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:19,代碼來源:Alias.java

示例2: internalXContent

import org.elasticsearch.index.query.QueryBuilder; //導入方法依賴的package包/類
@Override
protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject();
    if (keyedFilters == null && nonKeyedFilters == null) {
        throw new SearchSourceBuilderException("At least one filter must be set on filter aggregation [" + getName() + "]");
    }
    if (keyedFilters != null && nonKeyedFilters != null) {
        throw new SearchSourceBuilderException("Cannot add both keyed and non-keyed filters to filters aggregation");
    }

    if (keyedFilters != null) {
        builder.startObject(FiltersParser.FILTERS_FIELD.getPreferredName());
        for (Map.Entry<String, QueryBuilder> entry : keyedFilters.entrySet()) {
            builder.field(entry.getKey());
            entry.getValue().toXContent(builder, params);
        }
        builder.endObject();
    }
    if (nonKeyedFilters != null) {
        builder.startArray(FiltersParser.FILTERS_FIELD.getPreferredName());
        for (QueryBuilder filterBuilder : nonKeyedFilters) {
            filterBuilder.toXContent(builder, params);
        }
        builder.endArray();

    }
    if (otherBucketKey != null) {
        builder.field(FiltersParser.OTHER_BUCKET_KEY_FIELD.getPreferredName(), otherBucketKey);
    }
    if (otherBucket != null) {
        builder.field(FiltersParser.OTHER_BUCKET_FIELD.getPreferredName(), otherBucket);
    }
    return builder.endObject();
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:35,代碼來源:FiltersAggregationBuilder.java

示例3: parse

import org.elasticsearch.index.query.QueryBuilder; //導入方法依賴的package包/類
@Override
public Mapper parse(ParseContext context) throws IOException {
    QueryShardContext queryShardContext = this.queryShardContext.get();
    if (context.doc().getField(queryBuilderField.name()) != null) {
        // If a percolator query has been defined in an array object then multiple percolator queries
        // could be provided. In order to prevent this we fail if we try to parse more than one query
        // for the current document.
        throw new IllegalArgumentException("a document can only contain one percolator query");
    }

    XContentParser parser = context.parser();
    QueryBuilder queryBuilder = parseQueryBuilder(
            queryShardContext.newParseContext(parser), parser.getTokenLocation()
    );
    verifyQuery(queryBuilder);
    // Fetching of terms, shapes and indexed scripts happen during this rewrite:
    queryBuilder = queryBuilder.rewrite(queryShardContext);

    try (XContentBuilder builder = XContentFactory.contentBuilder(QUERY_BUILDER_CONTENT_TYPE)) {
        queryBuilder.toXContent(builder, new MapParams(Collections.emptyMap()));
        builder.flush();
        byte[] queryBuilderAsBytes = BytesReference.toBytes(builder.bytes());
        context.doc().add(new Field(queryBuilderField.name(), queryBuilderAsBytes, queryBuilderField.fieldType()));
    }

    Query query = toQuery(queryShardContext, mapUnmappedFieldAsString, queryBuilder);
    processQuery(query, context);
    return null;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:30,代碼來源:PercolatorFieldMapper.java

示例4: toXContent

import org.elasticsearch.index.query.QueryBuilder; //導入方法依賴的package包/類
protected static XContentBuilder toXContent(QueryBuilder query, XContentType contentType) throws IOException {
    XContentBuilder builder = XContentFactory.contentBuilder(contentType);
    if (randomBoolean()) {
        builder.prettyPrint();
    }
    query.toXContent(builder, ToXContent.EMPTY_PARAMS);
    return builder;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:9,代碼來源:AbstractQueryTestCase.java

示例5: filter

import org.elasticsearch.index.query.QueryBuilder; //導入方法依賴的package包/類
public AliasAction filter(QueryBuilder queryBuilder) {
    if (queryBuilder == null) {
        this.filter = null;
        return this;
    }
    try {
        XContentBuilder builder = XContentFactory.jsonBuilder();
        queryBuilder.toXContent(builder, ToXContent.EMPTY_PARAMS);
        builder.close();
        this.filter = builder.string();
        return this;
    } catch (IOException e) {
        throw new ElasticsearchGenerationException("Failed to build json for alias request", e);
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:16,代碼來源:AliasAction.java

示例6: filter

import org.elasticsearch.index.query.QueryBuilder; //導入方法依賴的package包/類
public static CompressedXContent filter(QueryBuilder filterBuilder) throws IOException {
    XContentBuilder builder = XContentFactory.jsonBuilder();
    filterBuilder.toXContent(builder, ToXContent.EMPTY_PARAMS);
    builder.close();
    return new CompressedXContent(builder.string());
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:7,代碼來源:ShardSearchTransportRequestTests.java

示例7: queryAsJson

import org.elasticsearch.index.query.QueryBuilder; //導入方法依賴的package包/類
public static String queryAsJson(QueryBuilder query) throws IOException {
  XContentBuilder x = XContentFactory.jsonBuilder();
  x.prettyPrint().lfAtEnd();
  query.toXContent(x, ToXContent.EMPTY_PARAMS);
  return x.string();
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:7,代碼來源:PredicateAnalyzer.java

示例8: checkGeneratedJson

import org.elasticsearch.index.query.QueryBuilder; //導入方法依賴的package包/類
/**
 * Call this method to check a valid json string representing the query under test against
 * it's generated json.
 *
 * Note: By the time of this writing (Nov 2015) all queries are taken from the query dsl
 * reference docs mirroring examples there. Here's how the queries were generated:
 *
 * <ul>
 * <li> Take a reference documentation example.
 * <li> Stick it into the createParseableQueryJson method of the respective query test.
 * <li> Manually check that what the QueryBuilder generates equals the input json ignoring default options.
 * <li> Put the manual checks into the assertQueryParsedFromJson method.
 * <li> Now copy the generated json including default options into createParseableQueryJson
 * <li> By now the roundtrip check for the json should be happy.
 * </ul>
 **/
public static void checkGeneratedJson(String expected, QueryBuilder source) throws IOException {
    // now assert that we actually generate the same JSON
    XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
    source.toXContent(builder, ToXContent.EMPTY_PARAMS);
    assertEquals(
            msg(expected, builder.string()),
            expected.replaceAll("\\s+", ""),
            builder.string().replaceAll("\\s+", ""));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:26,代碼來源:AbstractQueryTestCase.java


注:本文中的org.elasticsearch.index.query.QueryBuilder.toXContent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。