org.elasticsearch.common.xcontent.XContentParserUtils.parseTypedKeysObject()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(15.2k)|赞(0)|评价(0)|浏览(112)

本文整理了Java中org.elasticsearch.common.xcontent.XContentParserUtils.parseTypedKeysObject()方法的一些代码示例,展示了XContentParserUtils.parseTypedKeysObject()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XContentParserUtils.parseTypedKeysObject()方法的具体详情如下:
包路径:org.elasticsearch.common.xcontent.XContentParserUtils
类名称:XContentParserUtils
方法名:parseTypedKeysObject

XContentParserUtils.parseTypedKeysObject介绍

[英]This method expects that the current field name is the concatenation of a type, a delimiter and a name (ex: terms#foo where "terms" refers to the type of a registered NamedXContentRegistry.Entry, "#" is the delimiter and "foo" the name of the object to parse). The method splits the field's name to extract the type and name and then parses the object using the XContentParser#namedObject(Class,String,Object) method.
[中]此方法要求当前字段名是类型、分隔符和名称(例如:terms#foo,其中“terms”指的是注册名称的类型dxContentRegistry.Entry,“#”指的是分隔符,“foo”指的是要分析的对象的名称)。该方法拆分字段名称以提取类型和名称,然后使用XContentParser#namedObject(类、字符串、对象)方法解析对象。

代码示例

代码示例来源:origin: org.elasticsearch/elasticsearch

@SuppressWarnings("unchecked")
public static Suggestion<? extends Entry<? extends Option>> fromXContent(XContentParser parser) throws IOException {
  ensureExpectedToken(XContentParser.Token.START_ARRAY, parser.currentToken(), parser::getTokenLocation);
  SetOnce<Suggestion> suggestion = new SetOnce<>();
  XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Suggestion.class, suggestion::set);
  return suggestion.get();
}

代码示例来源:origin: org.elasticsearch/elasticsearch

public static Aggregations fromXContent(XContentParser parser) throws IOException {
    final List<Aggregation> aggregations = new ArrayList<>();
    XContentParser.Token token;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
      if (token == XContentParser.Token.START_OBJECT) {
        SetOnce<Aggregation> typedAgg = new SetOnce<>();
        String currentField = parser.currentName();
        parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class, typedAgg::set);
        if (typedAgg.get() != null) {
          aggregations.add(typedAgg.get());
        } else {
          throw new ParsingException(parser.getTokenLocation(),
              String.format(Locale.ROOT, "Could not parse aggregation keyed as [%s]", currentField));
        }
      }
    }
    return new Aggregations(aggregations);
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class,
    aggregations::add);

代码示例来源:origin: org.elasticsearch/elasticsearch

static <B extends ParsedBucket> B parseTermsBucketXContent(final XContentParser parser, final Supplier<B> bucketSupplier,
                                final CheckedBiConsumer<XContentParser, B, IOException> keyConsumer)
      throws IOException {
    final B bucket = bucketSupplier.get();
    final List<Aggregation> aggregations = new ArrayList<>();
    XContentParser.Token token;
    String currentFieldName = parser.currentName();
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
      if (token == XContentParser.Token.FIELD_NAME) {
        currentFieldName = parser.currentName();
      } else if (token.isValue()) {
        if (CommonFields.KEY_AS_STRING.getPreferredName().equals(currentFieldName)) {
          bucket.setKeyAsString(parser.text());
        } else if (CommonFields.KEY.getPreferredName().equals(currentFieldName)) {
          keyConsumer.accept(parser, bucket);
        } else if (CommonFields.DOC_COUNT.getPreferredName().equals(currentFieldName)) {
          bucket.setDocCount(parser.longValue());
        } else if (DOC_COUNT_ERROR_UPPER_BOUND_FIELD_NAME.getPreferredName().equals(currentFieldName)) {
          bucket.docCountError = parser.longValue();
          bucket.showDocCountError = true;
        }
      } else if (token == XContentParser.Token.START_OBJECT) {
        XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class,
            aggregations::add);
      }
    }
    bucket.setAggregations(new Aggregations(aggregations));
    return bucket;
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

aggregation.metadata = parser.map();
} else {
  XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class,
      aggregations::add);

代码示例来源:origin: org.elasticsearch/elasticsearch

XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class,
    aggregations::add);

代码示例来源:origin: org.elasticsearch/elasticsearch

keyConsumer.accept(parser, bucket);
} else {
  XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class,
    aggregations::add);

代码示例来源:origin: org.elasticsearch/elasticsearch

XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class,
    aggregations::add);

代码示例来源:origin: org.elasticsearch/elasticsearch

static ParsedBucket fromXContent(XContentParser parser, boolean keyed) throws IOException {
    final ParsedBucket bucket = new ParsedBucket();
    bucket.setKeyed(keyed);
    XContentParser.Token token = parser.currentToken();
    String currentFieldName = parser.currentName();
    if (keyed) {
      ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser::getTokenLocation);
      bucket.key = currentFieldName;
      ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
    }
    List<Aggregation> aggregations = new ArrayList<>();
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
      if (token == XContentParser.Token.FIELD_NAME) {
        currentFieldName = parser.currentName();
      } else if (token.isValue()) {
        if (CommonFields.DOC_COUNT.getPreferredName().equals(currentFieldName)) {
          bucket.setDocCount(parser.longValue());
        }
      } else if (token == XContentParser.Token.START_OBJECT) {
        XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class,
            aggregations::add);
      }
    }
    bucket.setAggregations(new Aggregations(aggregations));
    return bucket;
  }
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

public static Aggregations fromXContent(XContentParser parser) throws IOException {
    final List<Aggregation> aggregations = new ArrayList<>();
    XContentParser.Token token;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
      if (token == XContentParser.Token.START_OBJECT) {
        aggregations.add(XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class));
      }
    }
    return new Aggregations(aggregations);
  }
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

@SuppressWarnings("unchecked")
public static Suggestion<? extends Entry<? extends Option>> fromXContent(XContentParser parser) throws IOException {
  ensureExpectedToken(XContentParser.Token.FIELD_NAME, parser.currentToken(), parser::getTokenLocation);
  return XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Suggestion.class);
}

代码示例来源:origin: apache/servicemix-bundles

@SuppressWarnings("unchecked")
public static Suggestion<? extends Entry<? extends Option>> fromXContent(XContentParser parser) throws IOException {
  ensureExpectedToken(XContentParser.Token.START_ARRAY, parser.currentToken(), parser::getTokenLocation);
  SetOnce<Suggestion> suggestion = new SetOnce<>();
  XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Suggestion.class, suggestion::set);
  return suggestion.get();
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

@SuppressWarnings("unchecked")
public static Suggestion<? extends Entry<? extends Option>> fromXContent(XContentParser parser) throws IOException {
  ensureExpectedToken(XContentParser.Token.START_ARRAY, parser.currentToken(), parser::getTokenLocation);
  SetOnce<Suggestion> suggestion = new SetOnce<>();
  XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Suggestion.class, suggestion::set);
  return suggestion.get();
}

代码示例来源:origin: apache/servicemix-bundles

public static Aggregations fromXContent(XContentParser parser) throws IOException {
    final List<Aggregation> aggregations = new ArrayList<>();
    XContentParser.Token token;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
      if (token == XContentParser.Token.START_OBJECT) {
        SetOnce<Aggregation> typedAgg = new SetOnce<>();
        String currentField = parser.currentName();
        parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class, typedAgg::set);
        if (typedAgg.get() != null) {
          aggregations.add(typedAgg.get());
        } else {
          throw new ParsingException(parser.getTokenLocation(),
              String.format(Locale.ROOT, "Could not parse aggregation keyed as [%s]", currentField));
        }
      }
    }
    return new Aggregations(aggregations);
  }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

public static Aggregations fromXContent(XContentParser parser) throws IOException {
    final List<Aggregation> aggregations = new ArrayList<>();
    XContentParser.Token token;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
      if (token == XContentParser.Token.START_OBJECT) {
        SetOnce<Aggregation> typedAgg = new SetOnce<>();
        String currentField = parser.currentName();
        parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class, typedAgg::set);
        if (typedAgg.get() != null) {
          aggregations.add(typedAgg.get());
        } else {
          throw new ParsingException(parser.getTokenLocation(),
              String.format(Locale.ROOT, "Could not parse aggregation keyed as [%s]", currentField));
        }
      }
    }
    return new Aggregations(aggregations);
  }
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

static <B extends ParsedBucket> B parseTermsBucketXContent(final XContentParser parser, final Supplier<B> bucketSupplier,
                                final CheckedBiConsumer<XContentParser, B, IOException> keyConsumer)
      throws IOException {
    final B bucket = bucketSupplier.get();
    final List<Aggregation> aggregations = new ArrayList<>();
    XContentParser.Token token;
    String currentFieldName = parser.currentName();
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
      if (token == XContentParser.Token.FIELD_NAME) {
        currentFieldName = parser.currentName();
      } else if (token.isValue()) {
        if (CommonFields.KEY_AS_STRING.getPreferredName().equals(currentFieldName)) {
          bucket.setKeyAsString(parser.text());
        } else if (CommonFields.KEY.getPreferredName().equals(currentFieldName)) {
          keyConsumer.accept(parser, bucket);
        } else if (CommonFields.DOC_COUNT.getPreferredName().equals(currentFieldName)) {
          bucket.setDocCount(parser.longValue());
        } else if (DOC_COUNT_ERROR_UPPER_BOUND_FIELD_NAME.getPreferredName().equals(currentFieldName)) {
          bucket.docCountError = parser.longValue();
          bucket.showDocCountError = true;
        }
      } else if (token == XContentParser.Token.START_OBJECT) {
        aggregations.add(XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class));
      }
    }
    bucket.setAggregations(new Aggregations(aggregations));
    return bucket;
  }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

static <B extends ParsedBucket> B parseTermsBucketXContent(final XContentParser parser, final Supplier<B> bucketSupplier,
                                final CheckedBiConsumer<XContentParser, B, IOException> keyConsumer)
      throws IOException {
    final B bucket = bucketSupplier.get();
    final List<Aggregation> aggregations = new ArrayList<>();
    XContentParser.Token token;
    String currentFieldName = parser.currentName();
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
      if (token == XContentParser.Token.FIELD_NAME) {
        currentFieldName = parser.currentName();
      } else if (token.isValue()) {
        if (CommonFields.KEY_AS_STRING.getPreferredName().equals(currentFieldName)) {
          bucket.setKeyAsString(parser.text());
        } else if (CommonFields.KEY.getPreferredName().equals(currentFieldName)) {
          keyConsumer.accept(parser, bucket);
        } else if (CommonFields.DOC_COUNT.getPreferredName().equals(currentFieldName)) {
          bucket.setDocCount(parser.longValue());
        } else if (DOC_COUNT_ERROR_UPPER_BOUND_FIELD_NAME.getPreferredName().equals(currentFieldName)) {
          bucket.docCountError = parser.longValue();
          bucket.showDocCountError = true;
        }
      } else if (token == XContentParser.Token.START_OBJECT) {
        XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class,
            aggregations::add);
      }
    }
    bucket.setAggregations(new Aggregations(aggregations));
    return bucket;
  }
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

protected static <T extends ParsedSingleBucketAggregation> T parseXContent(final XContentParser parser, T aggregation, String name)
      throws IOException {
    aggregation.setName(name);
    XContentParser.Token token = parser.currentToken();
    String currentFieldName = parser.currentName();
    if (token == XContentParser.Token.FIELD_NAME) {
      token = parser.nextToken();
    }
    ensureExpectedToken(XContentParser.Token.START_OBJECT, token, parser::getTokenLocation);

    List<Aggregation> aggregations = new ArrayList<>();
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
      if (token == XContentParser.Token.FIELD_NAME) {
        currentFieldName = parser.currentName();
      } else if (token.isValue()) {
        if (CommonFields.DOC_COUNT.getPreferredName().equals(currentFieldName)) {
          aggregation.setDocCount(parser.longValue());
        }
      } else if (token == XContentParser.Token.START_OBJECT) {
        if (CommonFields.META.getPreferredName().equals(currentFieldName)) {
          aggregation.metadata = parser.map();
        } else {
          aggregations.add(XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class));
        }
      }
    }
    aggregation.aggregations = new Aggregations(aggregations);
    return aggregation;
  }
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

static ParsedBucket fromXContent(XContentParser parser, boolean keyed) throws IOException {
    final ParsedBucket bucket = new ParsedBucket();
    bucket.setKeyed(keyed);
    XContentParser.Token token = parser.currentToken();
    String currentFieldName = parser.currentName();
    if (keyed) {
      ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser::getTokenLocation);
      bucket.key = currentFieldName;
      ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
    }
    List<Aggregation> aggregations = new ArrayList<>();
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
      if (token == XContentParser.Token.FIELD_NAME) {
        currentFieldName = parser.currentName();
      } else if (token.isValue()) {
        if (CommonFields.DOC_COUNT.getPreferredName().equals(currentFieldName)) {
          bucket.setDocCount(parser.longValue());
        }
      } else if (token == XContentParser.Token.START_OBJECT) {
        aggregations.add(XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class));
      }
    }
    bucket.setAggregations(new Aggregations(aggregations));
    return bucket;
  }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

static ParsedBucket fromXContent(XContentParser parser, boolean keyed) throws IOException {
    final ParsedBucket bucket = new ParsedBucket();
    bucket.setKeyed(keyed);
    XContentParser.Token token = parser.currentToken();
    String currentFieldName = parser.currentName();
    if (keyed) {
      ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser::getTokenLocation);
      bucket.key = currentFieldName;
      ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
    }
    List<Aggregation> aggregations = new ArrayList<>();
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
      if (token == XContentParser.Token.FIELD_NAME) {
        currentFieldName = parser.currentName();
      } else if (token.isValue()) {
        if (CommonFields.DOC_COUNT.getPreferredName().equals(currentFieldName)) {
          bucket.setDocCount(parser.longValue());
        }
      } else if (token == XContentParser.Token.START_OBJECT) {
        XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class,
            aggregations::add);
      }
    }
    bucket.setAggregations(new Aggregations(aggregations));
    return bucket;
  }
}

相关文章