Skip to content

Commit

Permalink
Update API: Allow to update a document based on a script, closes #1583.
Browse files Browse the repository at this point in the history
  • Loading branch information
kimchy committed Jan 2, 2012
1 parent e582f6c commit 83d5084
Show file tree
Hide file tree
Showing 44 changed files with 1,906 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import org.elasticsearch.action.search.TransportSearchAction;
import org.elasticsearch.action.search.TransportSearchScrollAction;
import org.elasticsearch.action.search.type.*;
import org.elasticsearch.action.update.TransportUpdateAction;
import org.elasticsearch.common.inject.AbstractModule;

/**
Expand Down Expand Up @@ -126,6 +127,7 @@ protected void configure() {
bind(TransportIndexDeleteAction.class).asEagerSingleton();
bind(TransportShardDeleteAction.class).asEagerSingleton();
bind(TransportCountAction.class).asEagerSingleton();
bind(TransportUpdateAction.class).asEagerSingleton();

bind(TransportMultiGetAction.class).asEagerSingleton();
bind(TransportShardMultiGetAction.class).asEagerSingleton();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/elasticsearch/action/TransportActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class TransportActions {

public static final String INDEX = "indices/index/shard/index";

public static final String UPDATE = "update";

public static final String COUNT = "indices/count";

public static final String DELETE = "indices/index/shard/delete";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.elasticsearch.action.support.single.instance;

import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.Actions;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.unit.TimeValue;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

/**
*
*/
public abstract class InstanceShardOperationRequest implements ActionRequest {

public static final TimeValue DEFAULT_TIMEOUT = new TimeValue(1, TimeUnit.MINUTES);

protected TimeValue timeout = DEFAULT_TIMEOUT;

protected String index;
// -1 means its not set, allows to explicitly direct a request to a specific shard
protected int shardId = -1;

private boolean threadedListener = false;

protected InstanceShardOperationRequest() {
}

public InstanceShardOperationRequest(String index) {
this.index = index;
}

public TimeValue timeout() {
return timeout;
}

@Override
public ActionRequestValidationException validate() {
ActionRequestValidationException validationException = null;
if (index == null) {
validationException = Actions.addValidationError("index is missing", validationException);
}
return validationException;
}

public String index() {
return index;
}

InstanceShardOperationRequest index(String index) {
this.index = index;
return this;
}

/**
* Should the listener be called on a separate thread if needed.
*/
@Override
public boolean listenerThreaded() {
return threadedListener;
}

@Override
public InstanceShardOperationRequest listenerThreaded(boolean threadedListener) {
this.threadedListener = threadedListener;
return this;
}

@Override
public void readFrom(StreamInput in) throws IOException {
index = in.readUTF();
shardId = in.readInt();
timeout = TimeValue.readTimeValue(in);
// no need to pass threading over the network, they are always false when coming throw a thread pool
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeUTF(index);
out.writeInt(shardId);
timeout.writeTo(out);
}

public void beforeLocalFork() {
}
}

Loading

0 comments on commit 83d5084

Please sign in to comment.