本文整理匯總了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);
}
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}
}
示例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());
}
示例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();
}
示例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+", ""));
}