Package org.elasticsearch.search.facet

Examples of org.elasticsearch.search.facet.FacetPhaseExecutionException


        if (keyScript != null && valueScript != null) {
            return new ScriptHistogramFacetCollector(facetName, scriptLang, keyScript, valueScript, params, interval, comparatorType, context);
        }

        if (keyField == null) {
            throw new FacetPhaseExecutionException(facetName, "key field is required to be set for histogram facet, either using [field] or using [key_field]");
        }

        if (interval <= 0) {
            throw new FacetPhaseExecutionException(facetName, "[interval] is required to be set for histogram facet");
        }

        if (sFrom != null && sTo != null && keyField != null) {
            FieldMapper mapper = context.mapperService().smartNameFieldMapper(keyField);
            if (mapper == null) {
                throw new FacetPhaseExecutionException(facetName, "No mapping found for key_field [" + keyField + "]");
            }
            long from = ((Number) mapper.valueFromString(sFrom)).longValue();
            long to = ((Number) mapper.valueFromString(sTo)).longValue();

            if (valueField != null) {
View Full Code Here


                }
            }
        }

        if (mapScript == null) {
            throw new FacetPhaseExecutionException(facetName, "map_script field is required");
        }

        return new ScriptFacetCollector(scriptLang, initScript, mapScript, combineScript, reduceScript, params, reduceParams, context, client);
    }
View Full Code Here

                }
            }
        }

        if(valueField != null && distinctField != null)
            throw new FacetPhaseExecutionException(facetName, "[value_field] and [distinct_field] may not be used together");

        if(interval == null) {
            throw new FacetPhaseExecutionException(facetName, "[interval] is required to be set for histogram facet");
        }

        TimeZoneRounding.Builder tzRoundingBuilder;
        final DateFieldParser fieldParser = dateFieldParsers.get(interval);
        if(fieldParser != null) {
            tzRoundingBuilder = TimeZoneRounding.builder(fieldParser.parse(chronology));
        } else {
            // the interval is a time value?
            tzRoundingBuilder = TimeZoneRounding.builder(TimeValue.parseTimeValue(interval, null));
        }

        final TimeZoneRounding tzRounding = tzRoundingBuilder
                .preZone(preZone).postZone(postZone)
                .preZoneAdjustLargeInterval(preZoneAdjustLargeInterval)
                .preOffset(preOffset).postOffset(postOffset)
                .factor(factor)
                .build();

        final TypedFieldData keyFieldData = getKeyFieldData(keyField, context);
        if(keyFieldData == null)
            throw new FacetPhaseExecutionException(facetName, "[key_field] is required to be set for distinct date histogram facet");

        final TypedFieldData valueFieldData = getFieldData(valueField, context);
        final TypedFieldData distinctFieldData = getFieldData(distinctField, context);
        final TypedFieldData sliceFieldData = getFieldData(sliceField, context);
View Full Code Here

    private TypedFieldData getFieldData(final String fieldName, final SearchContext context) {
        if(fieldName != null) {
            final FieldMapper<?> mapper = context.smartNameFieldMapper(fieldName);
            if(mapper == null) {
                throw new FacetPhaseExecutionException(fieldName, "no mapping found for " + fieldName);
            }
            final FieldDataType fieldDataType = mapper.fieldDataType();
            final IndexFieldData fieldData = context.fieldData().getForField(mapper);
            return new TypedFieldData(fieldData, fieldDataType);
        }
View Full Code Here

    private TypedFieldData getKeyFieldData(final String fieldName, final SearchContext context) {
        if(fieldName != null) {
            final FieldMapper<?> mapper = context.smartNameFieldMapper(fieldName);
            if(mapper == null) {
                throw new FacetPhaseExecutionException(fieldName, "no mapping found for " + fieldName);
            }

            final Index index = context.mapperService().index();
            final Settings indexSettings = context.indexShard().indexSettings();
            final Names fieldNames = mapper.names();
View Full Code Here

        }
        FieldMapper keyFieldMapper = context.mapperService().smartNameFieldMapper(
                keyFieldName);
        if ((keyFieldMapper != null)
                && !(keyFieldMapper.fieldDataType().getType().equals(LatestFacetExecutor.keyDataType.getType()))) {
            throw new FacetPhaseExecutionException(facetName,
                    "key field must be of type long but is "
                            + keyFieldMapper.fieldDataType().getType());
        }

        FieldMapper tsFieldMapper = context.mapperService().smartNameFieldMapper(tsFieldName);
        if ((tsFieldMapper != null)
                && !(tsFieldMapper.fieldDataType().getType().equals(LatestFacetExecutor.tsDataType.getType()))) {
            throw new FacetPhaseExecutionException(facetName,
                    "ts field must be of type long but is "
                            + tsFieldMapper.fieldDataType().getType());
        }

        FieldMapper valueFieldMapper = context.mapperService().smartNameFieldMapper(valueFieldName);
        if (valueFieldMapper.fieldDataType().getType().equals("int") || valueFieldMapper.fieldDataType().getType().equals("long")) {
            IndexNumericFieldData valueFieldData = context.fieldData().getForField(valueFieldMapper);
            IndexNumericFieldData keyFieldData = context.fieldData().getForField(keyFieldMapper);
            IndexNumericFieldData tsFieldData = context.fieldData().getForField(tsFieldMapper);

            return new LatestFacetExecutor(keyFieldData, valueFieldData, tsFieldData, size, start,context.cacheRecycler());
        } else {
            throw new FacetPhaseExecutionException(facetName, "value field  is not of type int or long");
        }


    }
View Full Code Here

            }
        }

        // validation; opposed to the DateHistogramFacetParser the distinctField and interval is also required
        if (keyField == null) {
            throw new FacetPhaseExecutionException(facetName, "key field is required to be set for distinct histogram facet, either using [field] or using [key_field]");
        }
        FieldMapper keyMapper = context.smartNameFieldMapper(keyField);
        if (keyMapper == null) {
            throw new FacetPhaseExecutionException(facetName, "(key) field [" + keyField + "] not found");
        } else if (!keyMapper.fieldDataType().getType().equals("long")) {
            throw new FacetPhaseExecutionException(facetName, "(key) field [" + keyField + "] is not of type date");
        }
        if (distinctField == null) {
            throw new FacetPhaseExecutionException(facetName, "distinct field is required to be set for distinct histogram facet, either using [value_field] or using [distinctField]");
        }
        FieldMapper distinctFieldMapper = context.smartNameFieldMapper(distinctField);
        if (distinctFieldMapper == null) {
            throw new FacetPhaseExecutionException(facetName, "no mapping found for " + distinctField);
        }
        if (!intervalSet) {
            throw new FacetPhaseExecutionException(facetName, "[interval] is required to be set for distinct histogram facet");
        }


        // this is specific to the "Distinct" DateHistogram. Use a MutableDateTime to take care of the interval and rounding.
        // we set the rounding after we set the zone, for it to take affect
        if (sInterval != null) {
            int index = sInterval.indexOf(':');
            if (index != -1) {
                // set with rounding
                DateFieldParser fieldParser = dateFieldParsers.get(sInterval.substring(0, index));
                if (fieldParser == null) {
                    throw new FacetPhaseExecutionException(facetName, "failed to parse interval [" + sInterval + "] with custom rounding using built in intervals (year/month/...)");
                }
                DateTimeField field = fieldParser.parse(dateTime.getChronology());
                int rounding = this.rounding.get(sInterval.substring(index + 1));
                if (rounding == -1) {
                    throw new FacetPhaseExecutionException(facetName, "failed to parse interval [" + sInterval + "], rounding type [" + (sInterval.substring(index + 1)) + "] not found");
                }
                dateTime.setRounding(field, rounding);
            } else {
                DateFieldParser fieldParser = dateFieldParsers.get(sInterval);
                if (fieldParser != null) {
                    DateTimeField field = fieldParser.parse(dateTime.getChronology());
                    dateTime.setRounding(field, MutableDateTime.ROUND_FLOOR);
                } else {
                    // time interval
                    try {
                        interval = TimeValue.parseTimeValue(sInterval, null).millis();
                    } catch (Exception e) {
                        throw new FacetPhaseExecutionException(facetName, "failed to parse interval [" + sInterval + "], tried both as built in intervals (year/month/...) and as a time format");
                    }
                }
            }
        }



        if (distinctFieldMapper.fieldDataType().getType().equals("string")) {
            PagedBytesIndexFieldData distinctFieldData = context.fieldData().getForField(distinctFieldMapper);
            PackedArrayIndexFieldData keyIndexFieldData = context.fieldData().getForField(keyMapper);
            return new StringDistinctDateHistogramFacetExecutor(keyIndexFieldData, distinctFieldData, dateTime, interval, comparatorType, context.cacheRecycler());
        } else if (distinctFieldMapper.fieldDataType().getType().equals("long"))  {
            IndexNumericFieldData distinctFieldData = context.fieldData().getForField(distinctFieldMapper);
            IndexNumericFieldData keyIndexFieldData = context.fieldData().getForField(keyMapper);
            return new LongDistinctDateHistogramFacetExecutor(keyIndexFieldData, distinctFieldData, dateTime, interval, comparatorType, context.cacheRecycler());
        } else {
            throw new FacetPhaseExecutionException(facetName, "distinct field [" + distinctField + "] is not of type string or long");
        }
    }
View Full Code Here

                if ("params".equals(fieldName)) {
                    params = parser.map();
                } else if ("facet".equals(fieldName)) {
                  token = parser.nextToken();
                  if (token != XContentParser.Token.FIELD_NAME)
                    throw new FacetPhaseExecutionException(facetName, "No facet type defined under facet node");
                  String facetType = parser.currentName();
                  internalProcessor = processors.processor(facetType);
                    if (internalProcessor == null) {
                        throw new FacetPhaseExecutionException(facetName, "No facet type found for [" + facetType + "]");
                    }
                    ;
                    // Store underlying facet configuration
                  token = parser.nextToken(); // move the start of object...
                    ByteArrayOutputStream memstream = new ByteArrayOutputStream(20);
                    XContentGenerator generator = new JsonXContentGenerator(jsonFactory.createJsonGenerator(memstream));
                    XContentHelper.copyCurrentStructure(generator, parser);
                    generator.close();
                    memstream.close();
                    internalConfig = memstream.toByteArray(); // now we're at the end of the underlying config.
                                       
                    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT); // eat everything else under the "facet" clause
                 
                }
               
            }
            else if (token.isValue()) {
                if ("field".equals(fieldName)) {
                    keyField = parser.text();
                } else if ("key_field".equals(fieldName)) {
                    keyField = parser.text();
                } else if ("interval".equals(fieldName)) {
                    interval = parser.text();
                } else if ("time_zone".equals(fieldName) || "timeZone".equals(fieldName)) {
                    preZone = parseZone(parser, token);
                } else if ("pre_zone".equals(fieldName) || "preZone".equals(fieldName)) {
                    preZone = parseZone(parser, token);
                } else if ("pre_zone_adjust_large_interval".equals(fieldName) || "preZoneAdjustLargeInterval".equals(fieldName)) {
                    preZoneAdjustLargeInterval = parser.booleanValue();
                } else if ("post_zone".equals(fieldName) || "postZone".equals(fieldName)) {
                    postZone = parseZone(parser, token);
                } else if ("pre_offset".equals(fieldName) || "preOffset".equals(fieldName)) {
                    preOffset = parseOffset(parser.text());
                } else if ("post_offset".equals(fieldName) || "postOffset".equals(fieldName)) {
                    postOffset = parseOffset(parser.text());
                } else if ("factor".equals(fieldName)) {
                    factor = parser.floatValue();
                }
            }
        }
       
      
        if (keyField == null) {
            throw new FacetPhaseExecutionException(facetName, "key field is required to be set for histogram facet, either using [field] or using [key_field]");
        }

        FieldMapper mapper = context.smartNameFieldMapper(keyField);
        if (mapper == null) {
            throw new FacetPhaseExecutionException(facetName, "(key) field [" + keyField + "] not found");
        }
        if (mapper.fieldDataType() != FieldDataType.DefaultTypes.LONG) {
            throw new FacetPhaseExecutionException(facetName, "(key) field [" + keyField + "] is not of type date");
        }

        if (interval == null) {
            throw new FacetPhaseExecutionException(facetName, "[interval] is required to be set for histogram facet");
        }

        if (internalProcessor == null) {
            throw new FacetPhaseExecutionException(facetName, "faceted histogram misses an internal facet definition.");
        }

        TimeZoneRounding.Builder tzRoundingBuilder;
        DateFieldParser fieldParser = dateFieldParsers.get(interval);
        if (fieldParser != null) {
View Full Code Here

                }
            }
        }

        if(valueField != null && distinctField != null)
            throw new FacetPhaseExecutionException(facetName, "[value_field] and [distinct_field] may not be used together");

        if(interval == null) {
            throw new FacetPhaseExecutionException(facetName, "[interval] is required to be set for histogram facet");
        }

        TimeZoneRounding.Builder tzRoundingBuilder;
        final DateFieldParser fieldParser = dateFieldParsers.get(interval);
        if(fieldParser != null) {
View Full Code Here

    @SuppressWarnings("unchecked")
    private <IFD> IFD getFieldData(final String facetName, final String fieldName, final SearchContext context) {
        if(fieldName != null) {
            final FieldMapper<?> mapper = context.smartNameFieldMapper(fieldName);
            if(mapper == null) {
                throw new FacetPhaseExecutionException(facetName, "no mapping found for " + fieldName);
            }
            // This cast is a workaround to deal with issue #41
            return (IFD) context.fieldData().getForField(mapper);
        }
        return null;
View Full Code Here

TOP

Related Classes of org.elasticsearch.search.facet.FacetPhaseExecutionException

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.