Package org.elasticsearch.search

Examples of org.elasticsearch.search.SearchParseException


                sortFields.add(SORT_DOC);
            }
        } else {
            FieldMapper fieldMapper = context.mapperService().smartNameFieldMapper(fieldName);
            if (fieldMapper == null) {
                throw new SearchParseException(context, "No mapping found for [" + fieldName + "]");
            }
            sortFields.add(new SortField(fieldMapper.names().indexName(), fieldMapper.fieldDataType().newFieldComparatorSource(context.fieldDataCache(), missing), reverse));
        }
    }
View Full Code Here


                }
            }
        }

        if (script == null) {
            throw new SearchParseException(context, "_script sorting requires setting the script to sort by");
        }
        if (type == null) {
            throw new SearchParseException(context, "_script sorting requires setting the type of the script");
        }
        SearchScript searchScript = context.scriptService().search(context.lookup(), scriptLang, script, params);
        FieldComparatorSource fieldComparatorSource;
        if ("string".equals(type)) {
            fieldComparatorSource = StringFieldsFunctionDataComparator.comparatorSource(searchScript);
        } else if ("number".equals(type)) {
            fieldComparatorSource = DoubleFieldsFunctionDataComparator.comparatorSource(searchScript);
        } else {
            throw new SearchParseException(context, "custom script sort type [" + type + "] not supported");
        }
        return new SortField("_script", fieldComparatorSource, reverse);
    }
View Full Code Here

                    }
                }
            }
        }
        if (globalPreTags != null && globalPostTags == null) {
            throw new SearchParseException(context, "Highlighter global preTags are set, but global postTags are not set");
        }

        // now, go over and fill all fields with default values from the global state
        for (SearchContextHighlight.Field field : fields) {
            if (field.preTags() == null) {
View Full Code Here

                        if ("facet_filter".equals(facetFieldName) || "facetFilter".equals(facetFieldName)) {
                            filter = context.queryParserService().parseInnerFilter(parser);
                        } else {
                            FacetProcessor facetProcessor = facetProcessors.processor(facetFieldName);
                            if (facetProcessor == null) {
                                throw new SearchParseException(context, "No facet type found for [" + facetFieldName + "]");
                            }
                            facet = facetProcessor.parse(topLevelFieldName, parser, context);
                        }
                    } else if (token.isValue()) {
                        if ("global".equals(facetFieldName)) {
                            if (parser.booleanValue()) {
                                scope = ContextIndexSearcher.Scopes.GLOBAL;
                            }
                        } else if ("scope".equals(facetFieldName) || "_scope".equals(facetFieldName)) {
                            scope = parser.text();
                        } else if ("cache_filter".equals(facetFieldName) || "cacheFilter".equals(facetFieldName)) {
                            cacheFilter = parser.booleanValue();
                        } else if ("nested".equals(facetFieldName)) {
                            nestedPath = parser.text();
                        }
                    }
                }
                if (filter != null) {
                    if (cacheFilter) {
                        filter = context.filterCache().cache(filter);
                    }
                    facet.setFilter(filter);
                }

                if (nestedPath != null) {
                    // its a nested facet, wrap the collector with a facet one...
                    MapperService.SmartNameObjectMapper mapper = context.mapperService().smartNameObjectMapper(nestedPath);
                    if (mapper == null) {
                        throw new SearchParseException(context, "facet nested path [" + nestedPath + "] not found");
                    }
                    ObjectMapper objectMapper = mapper.mapper();
                    if (objectMapper == null) {
                        throw new SearchParseException(context, "facet nested path [" + nestedPath + "] not found");
                    }
                    if (!objectMapper.nested().isNested()) {
                        throw new SearchParseException(context, "facet nested path [" + nestedPath + "] is not nested");
                    }
                    facet = new NestedChildrenCollector(facet, context.filterCache().cache(NonNestedDocsFilter.INSTANCE), context.filterCache().cache(objectMapper.nestedTypeFilter()));
                }

                if (facet == null) {
                    throw new SearchParseException(context, "no facet type found for facet named [" + topLevelFieldName + "]");
                }

                if (facetCollectors == null) {
                    facetCollectors = Lists.newArrayList();
                }
View Full Code Here

                        String fieldName = parser.currentName();
                        parser.nextToken();
                        SearchParseElement element = getElementParsers().get(
                                fieldName);
                        if (element == null) {
                            throw new SearchParseException(context,
                                    "No parser for element [" + fieldName +
                                            "]");
                        }
                        element.parse(parser, context);
                    } else if (token == null) {
                        break;
                    }
                }
            }
            validate(context);
        } catch (Exception e) {
            String sSource = "_na_";
            try {
                sSource = XContentHelper.convertToJson(source, false);
            } catch (Throwable e1) {
                // ignore
            }
            throw new SearchParseException(context,
                    "Failed to parse source [" + sSource + "]", e);
        } finally {
            if (parser != null) {
                parser.close();
            }
View Full Code Here

    protected void validate(SearchIntoContext context) {
        if (context.hasFieldNames() && context.fieldNames().contains("_source")) {
            String index = context.mapperService().index().getName();
            for (String type : context.mapperService().types()) {
                if (!context.mapperService().documentMapper(type).sourceMapper().enabled()) {
                    throw new SearchParseException(context,
                            "The _source field of index " + index + " and type " + type + " is not stored.");
                }
            }
        }
    }
View Full Code Here

    }

    @Override
    protected void validate(SearchIntoContext context) {
        if (!context.hasFieldNames()) {
            throw new SearchParseException(context, "No fields defined");
        }

        for (String field : context.fieldNames()) {
            FieldMapper<?> mapper = context.mapperService().smartNameFieldMapper(
                    field);
            if (mapper == null && !field.equals(
                    "_version") && !field.startsWith(
                    FieldsParseElement.SCRIPT_FIELD_PREFIX)) {
                throw new SearchParseException(context,
                        "SearchInto field [" + field + "] does not exist in " +
                                "the mapping");
            }
        }
        super.validate(context);
View Full Code Here

     *
     * @param context
     */
    private void validate(ExportContext context) {
        if (!context.hasFieldNames()) {
            throw new SearchParseException(context, "No export fields defined");
        }
        for (String field : context.fieldNames()) {
            if (context.mapperService().name(field) == null && !field.equals("_version")) {
                throw new SearchParseException(context, "Export field [" + field + "] does not exist in the mapping");
            }
        }
        if (context.outputFile() != null) {
            if (context.outputCmdArray() != null || context.outputCmd() != null) {
                throw new SearchParseException(context, "Concurrent definition of 'output_cmd' and 'output_file'");
            }
        } else if (context.outputCmdArray() == null && context.outputCmd() == null) {
            throw new SearchParseException(context, "'output_cmd' or 'output_file' has not been defined");
        } else if (context.outputFile() == null && context.settings()) {
            throw new SearchParseException(context, "Parameter 'settings' requires usage of 'output_file'");
        } else if (context.outputFile() == null && context.mappings()) {
            throw new SearchParseException(context, "Parameter 'mappings' requires usage of 'output_file'");
        }
    }
View Full Code Here

                    if (token == XContentParser.Token.FIELD_NAME) {
                        String fieldName = parser.currentName();
                        parser.nextToken();
                        SearchParseElement element = elementParsers.get(fieldName);
                        if (element == null) {
                            throw new SearchParseException(context, "No parser for element [" + fieldName + "]");
                        }
                        element.parse(parser, context);
                    } else if (token == null) {
                        break;
                    }
                }
            }
            validate(context);
        } catch (Exception e) {
            String sSource = "_na_";
            try {
                sSource = XContentHelper.convertToJson(source, false);
            } catch (Throwable e1) {
                // ignore
            }
            throw new SearchParseException(context, "Failed to parse source [" + sSource + "]", e);
        } finally {
            if (parser != null) {
                parser.close();
            }
        }
View Full Code Here

                    if (token == XContentParser.Token.FIELD_NAME) {
                        String fieldName = parser.currentName();
                        parser.nextToken();
                        SearchParseElement element = elementParsers.get(fieldName);
                        if (element == null) {
                            throw new SearchParseException(context, "No parser for element [" + fieldName + "]");
                        }
                        element.parse(parser, context);
                    } else if (token == null) {
                        break;
                    }
                }
            }
            if (context.outputFile() == null) {
                directoryParseElement.setOutPutFile(context, DEFAULT_DIR);
                this.ensureDefaultDirectory(context);
            }
            context.mappings(true);
            context.settings(true);
        } catch (Exception e) {
            String sSource = "_na_";
            try {
                sSource = XContentHelper.convertToJson(source, false);
            } catch (Throwable e1) {
                // ignore
            }
            throw new SearchParseException(context, "Failed to parse source [" + sSource + "]", e);
        } finally {
            if (parser != null) {
                parser.close();
            }
        }
View Full Code Here

TOP

Related Classes of org.elasticsearch.search.SearchParseException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.