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


Java QueryShardException类代码示例

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


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

示例1: parse

import org.elasticsearch.index.query.QueryShardException; //导入依赖的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.QueryShardException; //导入依赖的package包/类
@Override
public SignificanceHeuristic parse(QueryParseContext context)
        throws IOException, QueryShardException {
    XContentParser parser = context.parser();
    String givenName = parser.currentName();
    boolean includeNegatives = false;
    boolean backgroundIsSuperset = true;
    XContentParser.Token token = parser.nextToken();
    while (!token.equals(XContentParser.Token.END_OBJECT)) {
        if (INCLUDE_NEGATIVES_FIELD.match(parser.currentName())) {
            parser.nextToken();
            includeNegatives = parser.booleanValue();
        } else if (BACKGROUND_IS_SUPERSET.match(parser.currentName())) {
            parser.nextToken();
            backgroundIsSuperset = parser.booleanValue();
        } else {
            throw new ElasticsearchParseException("failed to parse [{}] significance heuristic. unknown field [{}]", givenName, parser.currentName());
        }
        token = parser.nextToken();
    }
    return newHeuristic(includeNegatives, backgroundIsSuperset);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:NXYSignificanceHeuristic.java

示例3: parse

import org.elasticsearch.index.query.QueryShardException; //导入依赖的package包/类
@Override
public SignificanceHeuristic parse(QueryParseContext context) throws IOException, QueryShardException {
    XContentParser parser = context.parser();
    String givenName = parser.currentName();
    boolean backgroundIsSuperset = true;
    XContentParser.Token token = parser.nextToken();
    while (!token.equals(XContentParser.Token.END_OBJECT)) {
        if (BACKGROUND_IS_SUPERSET.match(parser.currentName())) {
            parser.nextToken();
            backgroundIsSuperset = parser.booleanValue();
        } else {
            throw new ElasticsearchParseException("failed to parse [{}] significance heuristic. unknown field [{}]", givenName, parser.currentName());
        }
        token = parser.nextToken();
    }
    return newHeuristic(true, backgroundIsSuperset);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:GND.java

示例4: resolveNested

import org.elasticsearch.index.query.QueryShardException; //导入依赖的package包/类
protected static Nested resolveNested(QueryShardContext context, String nestedPath, QueryBuilder nestedFilter) throws IOException {
    Nested nested = null;
    if (nestedPath != null) {
        BitSetProducer rootDocumentsFilter = context.bitsetFilter(Queries.newNonNestedFilter());
        ObjectMapper nestedObjectMapper = context.getObjectMapper(nestedPath);
        if (nestedObjectMapper == null) {
            throw new QueryShardException(context, "[nested] failed to find nested object under path [" + nestedPath + "]");
        }
        if (!nestedObjectMapper.nested().isNested()) {
            throw new QueryShardException(context, "[nested] nested object under path [" + nestedPath + "] is not of nested type");
        }
        Query innerDocumentsQuery;
        if (nestedFilter != null) {
            context.nestedScope().nextLevel(nestedObjectMapper);
            innerDocumentsQuery = QueryBuilder.rewriteQuery(nestedFilter, context).toFilter(context);
            context.nestedScope().previousLevel();
        } else {
            innerDocumentsQuery = nestedObjectMapper.nestedTypeFilter();
        }
        nested = new Nested(rootDocumentsFilter,  innerDocumentsQuery);
    }
    return nested;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:SortBuilder.java

示例5: doToQuery

import org.elasticsearch.index.query.QueryShardException; //导入依赖的package包/类
@Override
public Query doToQuery(QueryShardContext context, FeatureSet set, Map<String, Object> params) {
    List<String> missingParams = queryParams.stream()
            .filter((x) -> params == null || !params.containsKey(x))
            .collect(Collectors.toList());
    if (!missingParams.isEmpty()) {
        String names = missingParams.stream().collect(Collectors.joining(","));
        throw new IllegalArgumentException("Missing required param(s): [" + names + "]");
    }

    String query = MustacheUtils.execute(template, params);
    try {
        XContentParser parser = XContentFactory.xContent(query).createParser(context.getXContentRegistry(), query);
        QueryParseContext parserContext = context.newParseContext(parser);
        QueryBuilder queryBuilder = parserContext.parseInnerQueryBuilder().orElseThrow(
                () -> new ParsingException(parser.getTokenLocation(), "ltr inner query cannot be empty"));
        // XXX: QueryShardContext extends QueryRewriteContext (for now)
        return QueryBuilder.rewriteQuery(queryBuilder, context).toQuery(context);
    } catch (IOException |ParsingException|IllegalArgumentException e) {
        // wrap common exceptions as well so we can attach the feature's name to the stack
        throw new QueryShardException(context, "Cannot create query while parsing feature [" + name +"]", e);
    }
}
 
开发者ID:o19s,项目名称:elasticsearch-learning-to-rank,代码行数:24,代码来源:PrecompiledTemplateFeature.java

示例6: testPercolatorFieldMapperUnMappedField

import org.elasticsearch.index.query.QueryShardException; //导入依赖的package包/类
public void testPercolatorFieldMapperUnMappedField() throws Exception {
    addQueryMapping();
    MapperParsingException exception = expectThrows(MapperParsingException.class, () -> {
        mapperService.documentMapper(typeName).parse("test", typeName, "1", XContentFactory.jsonBuilder().startObject()
                .field(fieldName, termQuery("unmapped_field", "value"))
                .endObject().bytes());
    });
    assertThat(exception.getCause(), instanceOf(QueryShardException.class));
    assertThat(exception.getCause().getMessage(), equalTo("No field mapping can be found for the field with name [unmapped_field]"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:PercolatorFieldMapperTests.java

示例7: parse

import org.elasticsearch.index.query.QueryShardException; //导入依赖的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

示例8: parse

import org.elasticsearch.index.query.QueryShardException; //导入依赖的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 [percentage] significance heuristic. expected an empty object, but got [{}] instead", parser.currentToken());
    }
    return new PercentageScore();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:PercentageScore.java

示例9: build

import org.elasticsearch.index.query.QueryShardException; //导入依赖的package包/类
@Override
public SortFieldAndFormat build(QueryShardContext context) throws IOException {
    if (DOC_FIELD_NAME.equals(fieldName)) {
        if (order == SortOrder.DESC) {
            return SORT_DOC_REVERSE;
        } else {
            return SORT_DOC;
        }
    } else {
        MappedFieldType fieldType = context.fieldMapper(fieldName);
        if (fieldType == null) {
            if (unmappedType != null) {
                fieldType = context.getMapperService().unmappedFieldType(unmappedType);
            } else {
                throw new QueryShardException(context, "No mapping found for [" + fieldName + "] in order to sort on");
            }
        }

        MultiValueMode localSortMode = null;
        if (sortMode != null) {
            localSortMode = MultiValueMode.fromString(sortMode.toString());
        }

        boolean reverse = (order == SortOrder.DESC);
        if (localSortMode == null) {
            localSortMode = reverse ? MultiValueMode.MAX : MultiValueMode.MIN;
        }

        final Nested nested = resolveNested(context, nestedPath, nestedFilter);
        IndexFieldData<?> fieldData = context.getForField(fieldType);
        if (fieldData instanceof IndexNumericFieldData == false
                && (sortMode == SortMode.SUM || sortMode == SortMode.AVG || sortMode == SortMode.MEDIAN)) {
            throw new QueryShardException(context, "we only support AVG, MEDIAN and SUM on number based fields");
        }
        IndexFieldData.XFieldComparatorSource fieldComparatorSource = fieldData
                .comparatorSource(missing, localSortMode, nested);
        SortField field = new SortField(fieldType.name(), fieldComparatorSource, reverse);
        return new SortFieldAndFormat(field, fieldType.docValueFormat(null, null));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:41,代码来源:FieldSortBuilder.java

示例10: doToFunction

import org.elasticsearch.index.query.QueryShardException; //导入依赖的package包/类
@Override
protected ScoreFunction doToFunction(QueryShardContext context) {
    try {
        SearchScript searchScript = context.getSearchScript(script, ScriptContext.Standard.SEARCH);
        return new ScriptScoreFunction(script, searchScript);
    } catch (Exception e) {
        throw new QueryShardException(context, "script_score: the script could not be loaded", e);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:ScriptScoreFunctionBuilder.java

示例11: testQueryShardException

import org.elasticsearch.index.query.QueryShardException; //导入依赖的package包/类
public void testQueryShardException() throws IOException {
    QueryShardException ex = serialize(new QueryShardException(new Index("foo", "_na_"), "fobar", null));
    assertEquals(ex.getIndex().getName(), "foo");
    assertEquals(ex.getMessage(), "fobar");

    ex = serialize(new QueryShardException((Index) null, null, null));
    assertNull(ex.getIndex());
    assertNull(ex.getMessage());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:ExceptionSerializationTests.java

示例12: termQuery

import org.elasticsearch.index.query.QueryShardException; //导入依赖的package包/类
@Override
public Query termQuery(Object value, QueryShardContext context) {
    throw new QueryShardException(context, "Percolator fields are not searchable directly, use a percolate query instead");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:PercolatorFieldMapper.java

示例13: build

import org.elasticsearch.index.query.QueryShardException; //导入依赖的package包/类
@Override
public SortFieldAndFormat build(QueryShardContext context) throws IOException {
    final SearchScript searchScript = context.getSearchScript(script, ScriptContext.Standard.SEARCH);

    MultiValueMode valueMode = null;
    if (sortMode != null) {
        valueMode = MultiValueMode.fromString(sortMode.toString());
    }
    boolean reverse = (order == SortOrder.DESC);
    if (valueMode == null) {
        valueMode = reverse ? MultiValueMode.MAX : MultiValueMode.MIN;
    }

    final Nested nested = resolveNested(context, nestedPath, nestedFilter);
    final IndexFieldData.XFieldComparatorSource fieldComparatorSource;
    switch (type) {
        case STRING:
            fieldComparatorSource = new BytesRefFieldComparatorSource(null, null, valueMode, nested) {
                LeafSearchScript leafScript;
                @Override
                protected SortedBinaryDocValues getValues(LeafReaderContext context) throws IOException {
                    leafScript = searchScript.getLeafSearchScript(context);
                    final BinaryDocValues values = new BinaryDocValues() {
                        final BytesRefBuilder spare = new BytesRefBuilder();
                        @Override
                        public BytesRef get(int docID) {
                            leafScript.setDocument(docID);
                            spare.copyChars(leafScript.run().toString());
                            return spare.get();
                        }
                    };
                    return FieldData.singleton(values, null);
                }
                @Override
                protected void setScorer(Scorer scorer) {
                    leafScript.setScorer(scorer);
                }
            };
            break;
        case NUMBER:
            fieldComparatorSource = new DoubleValuesComparatorSource(null, Double.MAX_VALUE, valueMode, nested) {
                LeafSearchScript leafScript;
                @Override
                protected SortedNumericDoubleValues getValues(LeafReaderContext context) throws IOException {
                    leafScript = searchScript.getLeafSearchScript(context);
                    final NumericDoubleValues values = new NumericDoubleValues() {
                        @Override
                        public double get(int docID) {
                            leafScript.setDocument(docID);
                            return leafScript.runAsDouble();
                        }
                    };
                    return FieldData.singleton(values, null);
                }
                @Override
                protected void setScorer(Scorer scorer) {
                    leafScript.setScorer(scorer);
                }
            };
            break;
        default:
        throw new QueryShardException(context, "custom script sort type [" + type + "] not supported");
    }

    return new SortFieldAndFormat(new SortField("_script", fieldComparatorSource, reverse), DocValueFormat.RAW);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:67,代码来源:ScriptSortBuilder.java

示例14: termQuery

import org.elasticsearch.index.query.QueryShardException; //导入依赖的package包/类
@Override
public Query termQuery(Object value, QueryShardContext context) {
    throw new QueryShardException(context, "Binary fields do not support searching");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:BinaryFieldMapper.java

示例15: termQuery

import org.elasticsearch.index.query.QueryShardException; //导入依赖的package包/类
@Override
public Query termQuery(Object value, QueryShardContext context) {
    throw new QueryShardException(context, "The _source field is not searchable");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:SourceFieldMapper.java


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