@Override
 protected boolean resolveRequest(
     ClusterState state, UpdateRequest request, ActionListener<UpdateResponse> listener) {
   MetaData metaData = clusterService.state().metaData();
   String aliasOrIndex = request.index();
   request.routing((metaData.resolveIndexRouting(request.routing(), aliasOrIndex)));
   request.index(metaData.concreteIndex(request.index()));
   return true;
 }
  @Override
  protected boolean resolveRequest(
      ClusterState state, UpdateRequest request, ActionListener<UpdateResponse> listener) {
    MetaData metaData = clusterService.state().metaData();
    String aliasOrIndex = request.index();
    request.routing((metaData.resolveIndexRouting(request.routing(), aliasOrIndex)));
    request.index(metaData.concreteSingleIndex(request.index(), request.indicesOptions()));

    // Fail fast on the node that received the request, rather than failing when translating on the
    // index or delete request.
    if (request.routing() == null
        && state.getMetaData().routingRequired(request.index(), request.type())) {
      throw new RoutingMissingException(request.index(), request.type(), request.id());
    }
    return true;
  }
Exemplo n.º 3
0
 /* resolve the routing if needed */
 public void resolveRouting(MetaData metaData) {
   routing(metaData.resolveIndexRouting(parent, routing, index));
 }
Exemplo n.º 4
0
  public void process(
      MetaData metaData,
      String aliasOrIndex,
      @Nullable MappingMetaData mappingMd,
      boolean allowIdGeneration)
      throws ElasticsearchException {
    // resolve the routing if needed
    routing(metaData.resolveIndexRouting(routing, aliasOrIndex));
    // resolve timestamp if provided externally
    if (timestamp != null) {
      timestamp =
          MappingMetaData.Timestamp.parseStringTimestamp(
              timestamp,
              mappingMd != null
                  ? mappingMd.timestamp().dateTimeFormatter()
                  : TimestampFieldMapper.Defaults.DATE_TIME_FORMATTER);
    }
    // extract values if needed
    if (mappingMd != null) {
      MappingMetaData.ParseContext parseContext =
          mappingMd.createParseContext(id, routing, timestamp);

      if (parseContext.shouldParse()) {
        XContentParser parser = null;
        try {
          parser = XContentHelper.createParser(source);
          mappingMd.parse(parser, parseContext);
          if (parseContext.shouldParseId()) {
            id = parseContext.id();
          }
          if (parseContext.shouldParseRouting()) {
            routing = parseContext.routing();
          }
          if (parseContext.shouldParseTimestamp()) {
            timestamp = parseContext.timestamp();
            timestamp =
                MappingMetaData.Timestamp.parseStringTimestamp(
                    timestamp, mappingMd.timestamp().dateTimeFormatter());
          }
        } catch (Exception e) {
          throw new ElasticsearchParseException(
              "failed to parse doc to extract routing/timestamp", e);
        } finally {
          if (parser != null) {
            parser.close();
          }
        }
      }

      // might as well check for routing here
      if (mappingMd.routing().required() && routing == null) {
        throw new RoutingMissingException(index, type, id);
      }

      if (parent != null && !mappingMd.hasParentField()) {
        throw new ElasticsearchIllegalArgumentException(
            "Can't specify parent if no parent field has been configured");
      }
    } else {
      if (parent != null) {
        throw new ElasticsearchIllegalArgumentException(
            "Can't specify parent if no parent field has been configured");
      }
    }

    // generate id if not already provided and id generation is allowed
    if (allowIdGeneration) {
      if (id == null) {
        id(Strings.randomBase64UUID());
        // since we generate the id, change it to CREATE
        opType(IndexRequest.OpType.CREATE);
      }
    }

    // generate timestamp if not provided, we always have one post this stage...
    if (timestamp == null) {
      timestamp = Long.toString(System.currentTimeMillis());
    }
  }