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


Java QueryParseContext.parser方法代码示例

本文整理汇总了Java中org.elasticsearch.index.query.QueryParseContext.parser方法的典型用法代码示例。如果您正苦于以下问题:Java QueryParseContext.parser方法的具体用法?Java QueryParseContext.parser怎么用?Java QueryParseContext.parser使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.index.query.QueryParseContext的用法示例。


在下文中一共展示了QueryParseContext.parser方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parse

import org.elasticsearch.index.query.QueryParseContext; //导入方法依赖的package包/类
public static SignificanceHeuristic parse(QueryParseContext context)
        throws IOException, QueryShardException {
    XContentParser parser = context.parser();
    String heuristicName = parser.currentName();
    Script script = null;
    XContentParser.Token token;
    String currentFieldName = null;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token.equals(XContentParser.Token.FIELD_NAME)) {
            currentFieldName = parser.currentName();
        } else {
            if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName)) {
                script = Script.parse(parser);
            } else {
                throw new ElasticsearchParseException("failed to parse [{}] significance heuristic. unknown object [{}]", heuristicName, currentFieldName);
            }
        }
    }

    if (script == null) {
        throw new ElasticsearchParseException("failed to parse [{}] significance heuristic. no script found in script_heuristic", heuristicName);
    }
    return new ScriptHeuristic(script);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:ScriptHeuristic.java

示例2: parse

import org.elasticsearch.index.query.QueryParseContext; //导入方法依赖的package包/类
public InnerHitsSubSearchContext parse(QueryParseContext parserContext) throws IOException, QueryParsingException {
    String fieldName = null;
    XContentParser.Token token;
    String innerHitName = null;
    SubSearchContext subSearchContext = new SubSearchContext(SearchContext.current());
    try {
        XContentParser parser = parserContext.parser();
        while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
            if (token == XContentParser.Token.FIELD_NAME) {
                fieldName = parser.currentName();
            } else if (token.isValue()) {
                if ("name".equals(fieldName)) {
                    innerHitName = parser.textOrNull();
                } else {
                    parseCommonInnerHitOptions(parser, token, fieldName, subSearchContext, sortParseElement, sourceParseElement, highlighterParseElement, scriptFieldsParseElement, fieldDataFieldsParseElement);
                }
            } else {
                parseCommonInnerHitOptions(parser, token, fieldName, subSearchContext, sortParseElement, sourceParseElement, highlighterParseElement, scriptFieldsParseElement, fieldDataFieldsParseElement);
            }
        }
    } catch (Exception e) {
        throw new QueryParsingException(parserContext, "Failed to parse [_inner_hits]", e);
    }
    return new InnerHitsSubSearchContext(innerHitName, subSearchContext);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:26,代码来源:InnerHitsQueryParserHelper.java

示例3: fromXContent

import org.elasticsearch.index.query.QueryParseContext; //导入方法依赖的package包/类
public static ScriptScoreFunctionBuilder fromXContent(QueryParseContext parseContext)
        throws IOException, ParsingException {
    XContentParser parser = parseContext.parser();
    Script script = null;
    String currentFieldName = null;
    XContentParser.Token token;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else {
            if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName)) {
                script = Script.parse(parser);
            } else {
                throw new ParsingException(parser.getTokenLocation(), NAME + " query does not support [" + currentFieldName + "]");
            }
        }
    }

    if (script == null) {
        throw new ParsingException(parser.getTokenLocation(), NAME + " requires 'script' field");
    }

    return new ScriptScoreFunctionBuilder(script);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:ScriptScoreFunctionBuilder.java

示例4: parseFromXContent

import org.elasticsearch.index.query.QueryParseContext; //导入方法依赖的package包/类
public static RescoreBuilder<?> parseFromXContent(QueryParseContext parseContext) throws IOException {
    XContentParser parser = parseContext.parser();
    String fieldName = null;
    RescoreBuilder<?> rescorer = null;
    Integer windowSize = null;
    XContentParser.Token token;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            fieldName = parser.currentName();
        } else if (token.isValue()) {
            if (WINDOW_SIZE_FIELD.match(fieldName)) {
                windowSize = parser.intValue();
            } else {
                throw new ParsingException(parser.getTokenLocation(), "rescore doesn't support [" + fieldName + "]");
            }
        } else if (token == XContentParser.Token.START_OBJECT) {
            // we only have QueryRescorer at this point
            if (QueryRescorerBuilder.NAME.equals(fieldName)) {
                rescorer = QueryRescorerBuilder.fromXContent(parseContext);
            } else {
                throw new ParsingException(parser.getTokenLocation(), "rescore doesn't support rescorer with name [" + fieldName + "]");
            }
        } else {
            throw new ParsingException(parser.getTokenLocation(), "unexpected token [" + token + "] after [" + fieldName + "]");
        }
    }
    if (rescorer == null) {
        throw new ParsingException(parser.getTokenLocation(), "missing rescore type");
    }
    if (windowSize != null) {
        rescorer.windowSize(windowSize.intValue());
    }
    return rescorer;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:35,代码来源:RescoreBuilder.java

示例5: fromXContent

import org.elasticsearch.index.query.QueryParseContext; //导入方法依赖的package包/类
@Override
public Optional<SeqSpanQueryBuilder> fromXContent(QueryParseContext parseContext) throws IOException {
  XContentParser parser = parseContext.parser();
  SeqSpanQueryBuilder builder = new SeqSpanQueryBuilder();

  String currentFieldName = null;
  String fieldName = null;
  XContentParser.Token token = null;
  while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
    if (token == XContentParser.Token.START_OBJECT) {
      // skip
      System.out.println("start object " + token.isValue());
    } else if (token == XContentParser.Token.FIELD_NAME) {
      currentFieldName = parser.currentName();
      System.out.println(currentFieldName + " " + token.isValue());
    } else if (token.isValue()) {
      System.out.println("=== " + currentFieldName);
      if (SeqSpanQueryBuilder.START_TERM_FIELD.match(currentFieldName)) {
        System.out.println(parser.text());
        builder.setStartTerm(parser.text());
      } else if (SeqSpanQueryBuilder.END_TERM_FIELD.match(currentFieldName)) {
        System.out.println(parser.text());
        builder.setEndTerm(parser.text());
      } else if (SeqSpanQueryBuilder.SEQ_TERM_FIELD.match(currentFieldName)) {
        System.out.println(parser.text());
        builder.setSeqTerm(parser.text());
      } else if (SeqSpanQueryBuilder.MAX_SPAN_FIELD.match(currentFieldName)) {
        System.out.println(parser.intValue());
        builder.setMaxSpan(parser.intValue());
      } else {
        System.out.println(parser.text());
        builder.setFieldName(parser.text());
      }
    }
  }
  return Optional.of(builder);
}
 
开发者ID:sing1ee,项目名称:lucene-custom-query,代码行数:38,代码来源:SeqSpanQueryParser.java

示例6: parse

import org.elasticsearch.index.query.QueryParseContext; //导入方法依赖的package包/类
public static SignificanceHeuristic parse(QueryParseContext context)
        throws IOException, QueryShardException {
    XContentParser parser = context.parser();
    // move to the closing bracket
    if (!parser.nextToken().equals(XContentParser.Token.END_OBJECT)) {
        throw new ElasticsearchParseException(
                "failed to parse [jlh] significance heuristic. expected an empty object, but found [{}] instead",
                parser.currentToken());
    }
    return new JLHScore();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:JLHScore.java

示例7: parse

import org.elasticsearch.index.query.QueryParseContext; //导入方法依赖的package包/类
public static ChildrenAggregationBuilder parse(String aggregationName, QueryParseContext context) throws IOException {
    String childType = null;

    XContentParser.Token token;
    String currentFieldName = null;
    XContentParser parser = context.parser();
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token == XContentParser.Token.VALUE_STRING) {
            if ("type".equals(currentFieldName)) {
                childType = parser.text();
            } else {
                throw new ParsingException(parser.getTokenLocation(),
                        "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "].");
            }
        } else {
            throw new ParsingException(parser.getTokenLocation(), "Unexpected token " + token + " in [" + aggregationName + "].");
        }
    }

    if (childType == null) {
        throw new ParsingException(parser.getTokenLocation(),
                "Missing [child_type] field for children aggregation [" + aggregationName + "]");
    }


    return new ChildrenAggregationBuilder(aggregationName, childType);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:ChildrenAggregationBuilder.java

示例8: fromXContent

import org.elasticsearch.index.query.QueryParseContext; //导入方法依赖的package包/类
/**
 * Parses bodies of the kind
 *
 * <pre>
 * <code>
 * {
 *      "fieldname1" : {
 *          "origin" : "someValue",
 *          "scale" : "someValue"
 *      },
 *      "multi_value_mode" : "min"
 * }
 * </code>
 * </pre>
 */
@Override
public DFB fromXContent(QueryParseContext context) throws IOException, ParsingException {
    XContentParser parser = context.parser();
    String currentFieldName;
    XContentParser.Token token;
    MultiValueMode multiValueMode = DecayFunctionBuilder.DEFAULT_MULTI_VALUE_MODE;
    String fieldName = null;
    BytesReference functionBytes = null;
    while ((token = parser.nextToken()) == XContentParser.Token.FIELD_NAME) {
        currentFieldName = parser.currentName();
        token = parser.nextToken();
        if (token == XContentParser.Token.START_OBJECT) {
            fieldName = currentFieldName;
            XContentBuilder builder = XContentFactory.jsonBuilder();
            builder.copyCurrentStructure(parser);
            functionBytes = builder.bytes();
        } else if (MULTI_VALUE_MODE.match(currentFieldName)) {
            multiValueMode = MultiValueMode.fromString(parser.text());
        } else {
            throw new ParsingException(parser.getTokenLocation(), "malformed score function score parameters.");
        }
    }
    if (fieldName == null || functionBytes == null) {
        throw new ParsingException(parser.getTokenLocation(), "malformed score function score parameters.");
    }
    DFB functionBuilder = createFromBytes.apply(fieldName, functionBytes);
    functionBuilder.setMultiValueMode(multiValueMode);
    return functionBuilder;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:45,代码来源:DecayFunctionParser.java

示例9: parse

import org.elasticsearch.index.query.QueryParseContext; //导入方法依赖的package包/类
public static NestedAggregationBuilder parse(String aggregationName, QueryParseContext context) throws IOException {
    String path = null;

    XContentParser.Token token;
    String currentFieldName = null;
    XContentParser parser = context.parser();
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token == XContentParser.Token.VALUE_STRING) {
            if (NestedAggregator.PATH_FIELD.match(currentFieldName)) {
                path = parser.text();
            } else {
                throw new ParsingException(parser.getTokenLocation(),
                        "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "].");
            }
        } else {
            throw new ParsingException(parser.getTokenLocation(), "Unexpected token " + token + " in [" + aggregationName + "].");
        }
    }

    if (path == null) {
        // "field" doesn't exist, so we fall back to the context of the ancestors
        throw new ParsingException(parser.getTokenLocation(), "Missing [path] field for nested aggregation [" + aggregationName + "]");
    }

    return new NestedAggregationBuilder(aggregationName, path);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:29,代码来源:NestedAggregationBuilder.java

示例10: parse

import org.elasticsearch.index.query.QueryParseContext; //导入方法依赖的package包/类
public static ReverseNestedAggregationBuilder parse(String aggregationName, QueryParseContext context) throws IOException {
    String path = null;

    XContentParser.Token token;
    String currentFieldName = null;
    XContentParser parser = context.parser();
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token == XContentParser.Token.VALUE_STRING) {
            if ("path".equals(currentFieldName)) {
                path = parser.text();
            } else {
                throw new ParsingException(parser.getTokenLocation(),
                        "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "].");
            }
        } else {
            throw new ParsingException(parser.getTokenLocation(), "Unexpected token " + token + " in [" + aggregationName + "].");
        }
    }

    ReverseNestedAggregationBuilder factory = new ReverseNestedAggregationBuilder(
            aggregationName);
    if (path != null) {
        factory.path(path);
    }
    return factory;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:29,代码来源:ReverseNestedAggregationBuilder.java

示例11: fromXContent

import org.elasticsearch.index.query.QueryParseContext; //导入方法依赖的package包/类
public static RandomScoreFunctionBuilder fromXContent(QueryParseContext parseContext)
        throws IOException, ParsingException {
    XContentParser parser = parseContext.parser();
    RandomScoreFunctionBuilder randomScoreFunctionBuilder = new RandomScoreFunctionBuilder();
    String currentFieldName = null;
    XContentParser.Token token;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token.isValue()) {
            if ("seed".equals(currentFieldName)) {
                if (token == XContentParser.Token.VALUE_NUMBER) {
                    if (parser.numberType() == XContentParser.NumberType.INT) {
                        randomScoreFunctionBuilder.seed(parser.intValue());
                    } else if (parser.numberType() == XContentParser.NumberType.LONG) {
                        randomScoreFunctionBuilder.seed(parser.longValue());
                    } else {
                        throw new ParsingException(parser.getTokenLocation(), "random_score seed must be an int, long or string, not '"
                                + token.toString() + "'");
                    }
                } else if (token == XContentParser.Token.VALUE_STRING) {
                    randomScoreFunctionBuilder.seed(parser.text());
                } else {
                    throw new ParsingException(parser.getTokenLocation(), "random_score seed must be an int/long or string, not '"
                            + token.toString() + "'");
                }
            } else {
                throw new ParsingException(parser.getTokenLocation(), NAME + " query does not support [" + currentFieldName + "]");
            }
        }
    }
    return randomScoreFunctionBuilder;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:34,代码来源:RandomScoreFunctionBuilder.java

示例12: fromXContent

import org.elasticsearch.index.query.QueryParseContext; //导入方法依赖的package包/类
public static CategoryQueryContext fromXContent(QueryParseContext context) throws IOException {
    XContentParser parser = context.parser();
    XContentParser.Token token = parser.currentToken();
    Builder builder = builder();
    if (token == XContentParser.Token.START_OBJECT) {
        CATEGORY_PARSER.parse(parser, builder, null);
    } else if (token == XContentParser.Token.VALUE_STRING) {
        builder.setCategory(parser.text());
    } else {
        throw new ElasticsearchParseException("category context must be an object or string");
    }
    return builder.build();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:CategoryQueryContext.java

示例13: fromXContent

import org.elasticsearch.index.query.QueryParseContext; //导入方法依赖的package包/类
public static GeoQueryContext fromXContent(QueryParseContext context) throws IOException {
    XContentParser parser = context.parser();
    XContentParser.Token token = parser.currentToken();
    GeoQueryContext.Builder builder = new Builder();
    if (token == XContentParser.Token.START_OBJECT) {
        GEO_CONTEXT_PARSER.parse(parser, builder, null);
    } else if (token == XContentParser.Token.VALUE_STRING) {
        builder.setGeoPoint(GeoPoint.fromGeohash(parser.text()));
    } else {
        throw new ElasticsearchParseException("geo context must be an object or string");
    }
    return builder.build();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:GeoQueryContext.java

示例14: parse

import org.elasticsearch.index.query.QueryParseContext; //导入方法依赖的package包/类
public static ScriptedMetricAggregationBuilder parse(String aggregationName, QueryParseContext context) throws IOException {
    Script initScript = null;
    Script mapScript = null;
    Script combineScript = null;
    Script reduceScript = null;
    Map<String, Object> params = null;
    XContentParser.Token token;
    String currentFieldName = null;
    Set<String> scriptParameters = new HashSet<>();
    scriptParameters.add(INIT_SCRIPT_FIELD.getPreferredName());
    scriptParameters.add(MAP_SCRIPT_FIELD.getPreferredName());
    scriptParameters.add(COMBINE_SCRIPT_FIELD.getPreferredName());
    scriptParameters.add(REDUCE_SCRIPT_FIELD.getPreferredName());

    XContentParser parser = context.parser();
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token == XContentParser.Token.START_OBJECT || token == XContentParser.Token.VALUE_STRING) {
            if (INIT_SCRIPT_FIELD.match(currentFieldName)) {
                initScript = Script.parse(parser);
            } else if (MAP_SCRIPT_FIELD.match(currentFieldName)) {
                mapScript = Script.parse(parser);
            } else if (COMBINE_SCRIPT_FIELD.match(currentFieldName)) {
                combineScript = Script.parse(parser);
            } else if (REDUCE_SCRIPT_FIELD.match(currentFieldName)) {
                reduceScript = Script.parse(parser);
            } else if (token == XContentParser.Token.START_OBJECT &&
                    PARAMS_FIELD.match(currentFieldName)) {
                params = parser.map();
            } else {
                throw new ParsingException(parser.getTokenLocation(),
                        "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "].");
            }
        } else {
            throw new ParsingException(parser.getTokenLocation(), "Unexpected token " + token + " in [" + aggregationName + "].");
        }
    }

    if (mapScript == null) {
        throw new ParsingException(parser.getTokenLocation(), "map_script field is required in [" + aggregationName + "].");
    }

    ScriptedMetricAggregationBuilder factory = new ScriptedMetricAggregationBuilder(aggregationName);
    if (initScript != null) {
        factory.initScript(initScript);
    }
    if (mapScript != null) {
        factory.mapScript(mapScript);
    }
    if (combineScript != null) {
        factory.combineScript(combineScript);
    }
    if (reduceScript != null) {
        factory.reduceScript(reduceScript);
    }
    if (params != null) {
        factory.params(params);
    }
    return factory;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:62,代码来源:ScriptedMetricAggregationBuilder.java

示例15: parse

import org.elasticsearch.index.query.QueryParseContext; //导入方法依赖的package包/类
public static BucketSelectorPipelineAggregationBuilder parse(String reducerName, QueryParseContext context) throws IOException {
    XContentParser parser = context.parser();
    XContentParser.Token token;
    Script script = null;
    String currentFieldName = null;
    Map<String, String> bucketsPathsMap = null;
    GapPolicy gapPolicy = null;

    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token == XContentParser.Token.VALUE_STRING) {
            if (BUCKETS_PATH.match(currentFieldName)) {
                bucketsPathsMap = new HashMap<>();
                bucketsPathsMap.put("_value", parser.text());
            } else if (GAP_POLICY.match(currentFieldName)) {
                gapPolicy = GapPolicy.parse(context, parser.text(), parser.getTokenLocation());
            } else if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName)) {
                script = Script.parse(parser);
            } else {
                throw new ParsingException(parser.getTokenLocation(),
                        "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "].");
            }
        } else if (token == XContentParser.Token.START_ARRAY) {
            if (BUCKETS_PATH.match(currentFieldName)) {
                List<String> paths = new ArrayList<>();
                while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
                    String path = parser.text();
                    paths.add(path);
                }
                bucketsPathsMap = new HashMap<>();
                for (int i = 0; i < paths.size(); i++) {
                    bucketsPathsMap.put("_value" + i, paths.get(i));
                }
            } else {
                throw new ParsingException(parser.getTokenLocation(),
                        "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "].");
            }
        } else if (token == XContentParser.Token.START_OBJECT) {
            if (Script.SCRIPT_PARSE_FIELD.match(currentFieldName)) {
                script = Script.parse(parser);
            } else if (BUCKETS_PATH.match(currentFieldName)) {
                Map<String, Object> map = parser.map();
                bucketsPathsMap = new HashMap<>();
                for (Map.Entry<String, Object> entry : map.entrySet()) {
                    bucketsPathsMap.put(entry.getKey(), String.valueOf(entry.getValue()));
                }
            } else {
                throw new ParsingException(parser.getTokenLocation(),
                        "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "].");
            }
        } else {
            throw new ParsingException(parser.getTokenLocation(), "Unexpected token " + token + " in [" + reducerName + "].");
        }
    }

    if (bucketsPathsMap == null) {
        throw new ParsingException(parser.getTokenLocation(), "Missing required field [" + BUCKETS_PATH.getPreferredName()
                + "] for bucket_selector aggregation [" + reducerName + "]");
    }

    if (script == null) {
        throw new ParsingException(parser.getTokenLocation(), "Missing required field [" + Script.SCRIPT_PARSE_FIELD.getPreferredName()
                + "] for bucket_selector aggregation [" + reducerName + "]");
    }

    BucketSelectorPipelineAggregationBuilder factory =
            new BucketSelectorPipelineAggregationBuilder(reducerName, bucketsPathsMap, script);
    if (gapPolicy != null) {
        factory.gapPolicy(gapPolicy);
    }
    return factory;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:74,代码来源:BucketSelectorPipelineAggregationBuilder.java


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