当前位置: 首页>>代码示例>>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;未经允许,请勿转载。