whats up? doc...

This commit is contained in:
kimchy 2010-02-27 19:27:07 +02:00
parent a5790cab28
commit bf7ace79ea
28 changed files with 568 additions and 49 deletions

View File

@ -25,13 +25,24 @@ import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.util.Nullable;
import org.elasticsearch.util.Required;
import org.elasticsearch.util.Strings;
import org.elasticsearch.util.Unicode;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Arrays;
/**
* @author kimchy (Shay Banon)
* A request to count the number of documents matching a specific query. Best created with
* {@link org.elasticsearch.client.Requests#countRequest(String...)}.
*
* <p>The request requires the query source to be set either using {@link #querySource(org.elasticsearch.index.query.QueryBuilder)},
* or {@link #querySource(byte[])}.
*
* @author kimchy (shay.banon)
* @see CountResponse
* @see org.elasticsearch.client.Client#count(CountRequest)
* @see org.elasticsearch.client.Requests#countRequest(String...)
*/
public class CountRequest extends BroadcastOperationRequest {
@ -45,60 +56,111 @@ public class CountRequest extends BroadcastOperationRequest {
CountRequest() {
}
/**
* Constructs a new count request against the provided indices. No indices provided means it will
* run against all indices.
*/
public CountRequest(String... indices) {
super(indices, null);
}
/**
* Controls the operation threading model.
*/
@Override public CountRequest operationThreading(BroadcastOperationThreading operationThreading) {
super.operationThreading(operationThreading);
return this;
}
/**
* Should the listener be called on a separate thread if needed.
*/
@Override public CountRequest listenerThreaded(boolean threadedListener) {
super.listenerThreaded(threadedListener);
return this;
}
/**
* A query hint to optionally later be used when routing the request.
*/
public CountRequest queryHint(String queryHint) {
this.queryHint = queryHint;
return this;
}
/**
* The minimum score of the documents to include in the count.
*/
float minScore() {
return minScore;
}
/**
* The minimum score of the documents to include in the count. Defaults to <tt>-1</tt> which means all
* documents will be included in the count.
*/
public CountRequest minScore(float minScore) {
this.minScore = minScore;
return this;
}
/**
* The query source to execute.
*/
byte[] querySource() {
return querySource;
}
/**
* The query source to execute.
*
* @see org.elasticsearch.index.query.json.JsonQueryBuilders
*/
@Required public CountRequest querySource(QueryBuilder queryBuilder) {
return querySource(queryBuilder.buildAsBytes());
}
public CountRequest querySource(byte[] querySource) {
/**
* The query source to execute. It is preferable to use either {@link #querySource(byte[])}
* or {@link #querySource(org.elasticsearch.index.query.QueryBuilder)}.
*/
@Required public CountRequest querySource(String querySource) {
return querySource(Unicode.fromStringAsBytes(querySource));
}
/**
* The query source to execute.
*/
@Required public CountRequest querySource(byte[] querySource) {
this.querySource = querySource;
return this;
}
/**
* The query parse name to use. If not set, will use the default one.
*/
String queryParserName() {
return queryParserName;
}
/**
* The query parse name to use. If not set, will use the default one.
*/
public CountRequest queryParserName(String queryParserName) {
this.queryParserName = queryParserName;
return this;
}
/**
* The types of documents the query will run against. Defaults to all types.
*/
String[] types() {
return this.types;
}
/**
* The types of documents the query will run against. Defaults to all types.
*/
public CountRequest types(String... types) {
this.types = types;
return this;
@ -137,4 +199,8 @@ public class CountRequest extends BroadcastOperationRequest {
out.writeUTF(type);
}
}
@Override public String toString() {
return "[" + Arrays.toString(indices) + "][" + Arrays.toString(types) + "], querySource[" + Unicode.fromBytes(querySource) + "]";
}
}

View File

@ -28,7 +28,9 @@ import java.io.IOException;
import java.util.List;
/**
* @author kimchy (Shay Banon)
* The response of the count action.
*
* @author kimchy (shay.banon)
*/
public class CountResponse extends BroadcastOperationResponse {
@ -38,11 +40,14 @@ public class CountResponse extends BroadcastOperationResponse {
}
public CountResponse(long count, int successfulShards, int failedShards, List<ShardOperationFailedException> shardFailures) {
CountResponse(long count, int successfulShards, int failedShards, List<ShardOperationFailedException> shardFailures) {
super(successfulShards, failedShards, shardFailures);
this.count = count;
}
/**
* The count of documents matching the query provided.
*/
public long count() {
return count;
}

View File

@ -28,9 +28,11 @@ import java.io.DataOutput;
import java.io.IOException;
/**
* @author kimchy (Shay Banon)
* Internal count request executed directly against a specific index shard.
*
* @author kimchy (shay.banon)
*/
public class ShardCountRequest extends BroadcastShardOperationRequest {
class ShardCountRequest extends BroadcastShardOperationRequest {
private float minScore;
private byte[] querySource;

View File

@ -26,9 +26,11 @@ import java.io.DataOutput;
import java.io.IOException;
/**
* @author kimchy (Shay Banon)
* Internal count response of a shard count request executed directly against a specific shard.
*
* @author kimchy (shay.banon)
*/
public class ShardCountResponse extends BroadcastShardOperationResponse {
class ShardCountResponse extends BroadcastShardOperationResponse {
private long count;
@ -41,7 +43,7 @@ public class ShardCountResponse extends BroadcastShardOperationResponse {
this.count = count;
}
public long count() {
long count() {
return this.count;
}

View File

@ -43,7 +43,7 @@ import static com.google.common.collect.Lists.*;
import static org.elasticsearch.action.Actions.*;
/**
* @author kimchy (Shay Banon)
* @author kimchy (shay.banon)
*/
public class TransportCountAction extends TransportBroadcastOperationAction<CountRequest, CountResponse, ShardCountRequest, ShardCountResponse> {

View File

@ -0,0 +1,23 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search 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.
*/
/**
* Count action.
*/
package org.elasticsearch.action.count;

View File

@ -31,17 +31,37 @@ import java.io.IOException;
import static org.elasticsearch.action.Actions.*;
/**
* @author kimchy (Shay Banon)
* A request to delete a document from an index based on its type and id. Best created using
* {@link org.elasticsearch.client.Requests#deleteRequest(String)}.
*
* <p>The operation requires the {@link #index()}, {@link #type(String)} and {@link #id(String)} to
* be set.
*
* @author kimchy (shay.banon)
* @see DeleteResponse
* @see org.elasticsearch.client.Client#delete(DeleteRequest)
* @see org.elasticsearch.client.Requests#deleteRequest(String)
*/
public class DeleteRequest extends ShardReplicationOperationRequest {
private String type;
private String id;
/**
* Constructs a new delete request against the specified index. The {@link #type(String)} and {@link #id(String)}
* must be set.
*/
public DeleteRequest(String index) {
this.index = index;
}
/**
* Constructs a new delete request against the specified index with the type and id.
*
* @param index The index to get the document from
* @param type The type of the document
* @param id The id of the document
*/
public DeleteRequest(String index, String type, String id) {
this.index = index;
this.type = type;
@ -62,34 +82,55 @@ public class DeleteRequest extends ShardReplicationOperationRequest {
return validationException;
}
/**
* Should the listener be called on a separate thread if needed.
*/
@Override public DeleteRequest listenerThreaded(boolean threadedListener) {
super.listenerThreaded(threadedListener);
return this;
}
/**
* Controls if the operation will be executed on a separate thread when executed locally.
*/
@Override public DeleteRequest operationThreaded(boolean threadedOperation) {
super.operationThreaded(threadedOperation);
return this;
}
/**
* The type of the document to delete.
*/
String type() {
return type;
}
/**
* Sets the type of the document to delete.
*/
@Required public DeleteRequest type(String type) {
this.type = type;
return this;
}
/**
* The id of the document to delete.
*/
String id() {
return id;
}
/**
* Sets the id of the document to delete.
*/
@Required public DeleteRequest id(String id) {
this.id = id;
return this;
}
/**
* A timeout to wait if the index operation can't be performed immediately. Defaults to <tt>1m</tt>.
*/
public DeleteRequest timeout(TimeValue timeout) {
this.timeout = timeout;
return this;
@ -106,4 +147,8 @@ public class DeleteRequest extends ShardReplicationOperationRequest {
out.writeUTF(type);
out.writeUTF(id);
}
@Override public String toString() {
return "[" + index + "][" + type + "][" + id + "]";
}
}

View File

@ -27,7 +27,11 @@ import java.io.DataOutput;
import java.io.IOException;
/**
* @author kimchy (Shay Banon)
* The response of the delete action.
*
* @author kimchy (shay.banon)
* @see org.elasticsearch.action.delete.DeleteRequest
* @see org.elasticsearch.client.Client#delete(DeleteRequest)
*/
public class DeleteResponse implements ActionResponse, Streamable {
@ -41,24 +45,33 @@ public class DeleteResponse implements ActionResponse, Streamable {
}
public DeleteResponse(String index, String type, String id) {
DeleteResponse(String index, String type, String id) {
this.index = index;
this.id = id;
this.type = type;
}
/**
* The index the document was deleted from.
*/
public String index() {
return this.index;
}
public String id() {
return this.id;
}
/**
* The type of the document deleted.
*/
public String type() {
return this.type;
}
/**
* The id of the document deleted.
*/
public String id() {
return this.id;
}
@Override public void readFrom(DataInput in) throws IOException, ClassNotFoundException {
index = in.readUTF();
id = in.readUTF();

View File

@ -37,7 +37,9 @@ import org.elasticsearch.transport.TransportService;
import org.elasticsearch.util.settings.Settings;
/**
* @author kimchy (Shay Banon)
* Performs the delete operation.
*
* @author kimchy (shay.banon)
*/
public class TransportDeleteAction extends TransportShardReplicationOperationAction<DeleteRequest, DeleteResponse> {

View File

@ -0,0 +1,23 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search 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.
*/
/**
* Delete action.
*/
package org.elasticsearch.action.delete;

View File

@ -19,18 +19,32 @@
package org.elasticsearch.action.deletebyquery;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.support.replication.IndicesReplicationOperationRequest;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.util.Required;
import org.elasticsearch.util.Strings;
import org.elasticsearch.util.TimeValue;
import org.elasticsearch.util.Unicode;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Arrays;
import static org.elasticsearch.action.Actions.*;
/**
* @author kimchy (Shay Banon)
* A request to delete all documents that matching a specific query. Best created with
* {@link org.elasticsearch.client.Requests#deleteByQueryRequest(String...)}.
*
* <p>The request requires the query source to be set either using {@link #querySource(org.elasticsearch.index.query.QueryBuilder)},
* or {@link #querySource(byte[])}.
*
* @author kimchy (shay.banon)
* @see DeleteByQueryResponse
* @see org.elasticsearch.client.Requests#deleteByQueryRequest(String...)
* @see org.elasticsearch.client.Client#deleteByQuery(DeleteByQueryRequest)
*/
public class DeleteByQueryRequest extends IndicesReplicationOperationRequest {
@ -38,6 +52,10 @@ public class DeleteByQueryRequest extends IndicesReplicationOperationRequest {
private String queryParserName;
private String[] types = Strings.EMPTY_ARRAY;
/**
* Constructs a new delete by query request to run against the provided indices. No indices means
* it will run against all indices.
*/
public DeleteByQueryRequest(String... indices) {
this.indices = indices;
}
@ -45,42 +63,87 @@ public class DeleteByQueryRequest extends IndicesReplicationOperationRequest {
DeleteByQueryRequest() {
}
/**
* Should the listener be called on a separate thread if needed.
*/
@Override public DeleteByQueryRequest listenerThreaded(boolean threadedListener) {
super.listenerThreaded(threadedListener);
return this;
}
@Override public ActionRequestValidationException validate() {
ActionRequestValidationException validationException = super.validate();
if (querySource == null) {
validationException = addValidationError("query is missing", validationException);
}
return validationException;
}
/**
* The query source to execute.
*/
byte[] querySource() {
return querySource;
}
/**
* The query source to execute.
*
* @see org.elasticsearch.index.query.json.JsonQueryBuilders
*/
@Required public DeleteByQueryRequest querySource(QueryBuilder queryBuilder) {
return querySource(queryBuilder.buildAsBytes());
}
/**
* The query source to execute. It is preferable to use either {@link #querySource(byte[])}
* or {@link #querySource(org.elasticsearch.index.query.QueryBuilder)}.
*/
@Required public DeleteByQueryRequest querySource(String querySource) {
return querySource(Unicode.fromStringAsBytes(querySource));
}
/**
* The query source to execute.
*/
@Required public DeleteByQueryRequest querySource(byte[] querySource) {
this.querySource = querySource;
return this;
}
/**
* The query parse name to use. If not set, will use the default one.
*/
String queryParserName() {
return queryParserName;
}
/**
* The query parse name to use. If not set, will use the default one.
*/
public DeleteByQueryRequest queryParserName(String queryParserName) {
this.queryParserName = queryParserName;
return this;
}
/**
* The types of documents the query will run against. Defaults to all types.
*/
String[] types() {
return this.types;
}
/**
* The types of documents the query will run against. Defaults to all types.
*/
public DeleteByQueryRequest types(String... types) {
this.types = types;
return this;
}
/**
* A timeout to wait if the delete by query operation can't be performed immediately. Defaults to <tt>1m</tt>.
*/
public DeleteByQueryRequest timeout(TimeValue timeout) {
this.timeout = timeout;
return this;
@ -106,4 +169,8 @@ public class DeleteByQueryRequest extends IndicesReplicationOperationRequest {
out.writeUTF(queryParserName);
}
}
@Override public String toString() {
return "[" + Arrays.toString(indices) + "][" + Arrays.toString(types) + "], querySource[" + Unicode.fromBytes(querySource) + "]";
}
}

View File

@ -25,26 +25,41 @@ import org.elasticsearch.util.io.Streamable;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* @author kimchy (Shay Banon)
*/
public class DeleteByQueryResponse implements ActionResponse, Streamable {
import static com.google.common.collect.Maps.*;
private Map<String, IndexDeleteByQueryResponse> indexResponses = new HashMap<String, IndexDeleteByQueryResponse>();
/**
* The response of delete by query action. Holds the {@link IndexDeleteByQueryResponse}s from all the
* different indices.
*
* @author kimchy (shay.banon)
*/
public class DeleteByQueryResponse implements ActionResponse, Streamable, Iterable<IndexDeleteByQueryResponse> {
private Map<String, IndexDeleteByQueryResponse> indices = newHashMap();
DeleteByQueryResponse() {
}
public Map<String, IndexDeleteByQueryResponse> indices() {
return indexResponses;
@Override public Iterator<IndexDeleteByQueryResponse> iterator() {
return indices.values().iterator();
}
/**
* The responses from all the different indices.
*/
public Map<String, IndexDeleteByQueryResponse> indices() {
return indices;
}
/**
* The response of a specific index.
*/
public IndexDeleteByQueryResponse index(String index) {
return indexResponses.get(index);
return indices.get(index);
}
@Override public void readFrom(DataInput in) throws IOException, ClassNotFoundException {
@ -52,13 +67,13 @@ public class DeleteByQueryResponse implements ActionResponse, Streamable {
for (int i = 0; i < size; i++) {
IndexDeleteByQueryResponse response = new IndexDeleteByQueryResponse();
response.readFrom(in);
indexResponses.put(response.index(), response);
indices.put(response.index(), response);
}
}
@Override public void writeTo(DataOutput out) throws IOException {
out.writeInt(indexResponses.size());
for (IndexDeleteByQueryResponse indexResponse : indexResponses.values()) {
out.writeInt(indices.size());
for (IndexDeleteByQueryResponse indexResponse : indices.values()) {
indexResponse.writeTo(out);
}
}

View File

@ -33,7 +33,9 @@ import java.io.IOException;
import static org.elasticsearch.action.Actions.*;
/**
* @author kimchy (Shay Banon)
* Delete by query request to execute on a specific index.
*
* @author kimchy (shay.banon)
*/
public class IndexDeleteByQueryRequest extends IndexReplicationOperationRequest {

View File

@ -27,7 +27,9 @@ import java.io.DataOutput;
import java.io.IOException;
/**
* @author kimchy (Shay Banon)
* Delete by query response executed on a specific index.
*
* @author kimchy (shay.banon)
*/
public class IndexDeleteByQueryResponse implements ActionResponse, Streamable {
@ -47,18 +49,30 @@ public class IndexDeleteByQueryResponse implements ActionResponse, Streamable {
}
/**
* The index the delete by query operation was executed against.
*/
public String index() {
return this.index;
}
/**
* The total number of shards the delete by query was executed on.
*/
public int totalShards() {
return failedShards + successfulShards;
}
/**
* The successful number of shards the delete by query was executed on.
*/
public int successfulShards() {
return successfulShards;
}
/**
* The failed number of shards the delete by query was executed on.
*/
public int failedShards() {
return failedShards;
}

View File

@ -31,7 +31,9 @@ import java.io.IOException;
import static org.elasticsearch.action.Actions.*;
/**
* @author kimchy (Shay Banon)
* Delete by query request to execute on a specific shard.
*
* @author kimchy (shay.banon)
*/
public class ShardDeleteByQueryRequest extends ShardReplicationOperationRequest {

View File

@ -27,7 +27,9 @@ import java.io.DataOutput;
import java.io.IOException;
/**
* @author kimchy (Shay Banon)
* Delete by query response executed on a specific shard.
*
* @author kimchy (shay.banon)
*/
public class ShardDeleteByQueryResponse implements ActionResponse, Streamable {

View File

@ -0,0 +1,23 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search 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.
*/
/**
* Delete by query action.
*/
package org.elasticsearch.action.deletebyquery;

View File

@ -101,4 +101,8 @@ public class GetRequest extends SingleOperationRequest {
@Override public void writeTo(DataOutput out) throws IOException {
super.writeTo(out);
}
@Override public String toString() {
return "[" + index + "][" + type + "][" + id + "]";
}
}

View File

@ -270,6 +270,6 @@ public class IndexRequest extends ShardReplicationOperationRequest {
}
@Override public String toString() {
return "IndexAction [" + index + "][" + type + "][" + id + "], source [" + Unicode.fromBytes(source) + "]";
return "[" + index + "][" + type + "][" + id + "], source[" + Unicode.fromBytes(source) + "]";
}
}

View File

@ -26,7 +26,9 @@ import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.search.Scroll;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.util.Bytes;
import org.elasticsearch.util.Required;
import org.elasticsearch.util.Strings;
import org.elasticsearch.util.Unicode;
import java.io.DataInput;
import java.io.DataOutput;
@ -35,7 +37,15 @@ import java.io.IOException;
import static org.elasticsearch.search.Scroll.*;
/**
* A more like this request allowing to search for documents that a "like" the provided document. The document
* to check against to fetched based on the index, type and id provided. Best created with {@link org.elasticsearch.client.Requests#moreLikeThisRequest(String)}.
*
* <p>Note, the {@link #index()}, {@link #type(String)} and {@link #id(String)} are required.
*
* @author kimchy (shay.banon)
* @see org.elasticsearch.client.Client#moreLikeThis(MoreLikeThisRequest)
* @see org.elasticsearch.client.Requests#moreLikeThisRequest(String)
* @see org.elasticsearch.action.search.SearchResponse
*/
public class MoreLikeThisRequest implements ActionRequest {
@ -68,161 +78,285 @@ public class MoreLikeThisRequest implements ActionRequest {
private boolean threadedListener = false;
public MoreLikeThisRequest() {
MoreLikeThisRequest() {
}
/**
* Constructs a new more like this request for a document that will be fetch from the provided index.
* Use {@link #type(String)} and {@link #id(String)} to specificy the document to load.
*/
public MoreLikeThisRequest(String index) {
this.index = index;
}
/**
* The index to load the document from which the "like" query will run with.
*/
public String index() {
return index;
}
/**
* The type of document to load from which the "like" query will rutn with.
*/
public String type() {
return type;
}
public MoreLikeThisRequest type(String type) {
/**
* The type of document to load from which the "like" query will rutn with.
*/
@Required public MoreLikeThisRequest type(String type) {
this.type = type;
return this;
}
/**
* The id of document to load from which the "like" query will rutn with.
*/
public String id() {
return id;
}
public MoreLikeThisRequest id(String id) {
/**
* The id of document to load from which the "like" query will rutn with.
*/
@Required public MoreLikeThisRequest id(String id) {
this.id = id;
return this;
}
/**
* The fields of the document to use in order to find documents "like" this one. Defaults to run
* against all the document fields.
*/
public String[] fields() {
return this.fields;
}
/**
* The fields of the document to use in order to find documents "like" this one. Defaults to run
* against all the document fields.
*/
public MoreLikeThisRequest fields(String... fields) {
this.fields = fields;
return this;
}
/**
* The percent of the terms to match for each field. Defaults to <tt>0.3f</tt>.
*/
public MoreLikeThisRequest percentTermsToMatch(float percentTermsToMatch) {
this.percentTermsToMatch = percentTermsToMatch;
return this;
}
/**
* The percent of the terms to match for each field. Defaults to <tt>0.3f</tt>.
*/
public float percentTermsToMatch() {
return this.percentTermsToMatch;
}
/**
* The frequency below which terms will be ignored in the source doc. Defaults to <tt>2</tt>.
*/
public MoreLikeThisRequest minTermFrequency(int minTermFrequency) {
this.minTermFrequency = minTermFrequency;
return this;
}
/**
* The frequency below which terms will be ignored in the source doc. Defaults to <tt>2</tt>.
*/
public int minTermFrequency() {
return this.minTermFrequency;
}
/**
* The maximum number of query terms that will be included in any generated query. Defaults to <tt>25</tt>.
*/
public MoreLikeThisRequest maxQueryTerms(int maxQueryTerms) {
this.maxQueryTerms = maxQueryTerms;
return this;
}
/**
* The maximum number of query terms that will be included in any generated query. Defaults to <tt>25</tt>.
*/
public int maxQueryTerms() {
return this.maxQueryTerms;
}
/**
* Any word in this set is considered "uninteresting" and ignored.
*
* <p>Even if your Analyzer allows stopwords, you might want to tell the MoreLikeThis code to ignore them, as
* for the purposes of document similarity it seems reasonable to assume that "a stop word is never interesting".
*
* <p>Defaults to no stop words.
*/
public MoreLikeThisRequest stopWords(String... stopWords) {
this.stopWords = stopWords;
return this;
}
/**
* Any word in this set is considered "uninteresting" and ignored.
*
* <p>Even if your Analyzer allows stopwords, you might want to tell the MoreLikeThis code to ignore them, as
* for the purposes of document similarity it seems reasonable to assume that "a stop word is never interesting".
*
* <p>Defaults to no stop words.
*/
public String[] stopWords() {
return this.stopWords;
}
/**
* The frequency at which words will be ignored which do not occur in at least this
* many docs. Defaults to <tt>5</tt>.
*/
public MoreLikeThisRequest minDocFreq(int minDocFreq) {
this.minDocFreq = minDocFreq;
return this;
}
/**
* The frequency at which words will be ignored which do not occur in at least this
* many docs. Defaults to <tt>5</tt>.
*/
public int minDocFreq() {
return this.minDocFreq;
}
/**
* The maximum frequency in which words may still appear. Words that appear
* in more than this many docs will be ignored. Defaults to unbounded.
*/
public MoreLikeThisRequest maxDocFreq(int maxDocFreq) {
this.maxDocFreq = maxDocFreq;
return this;
}
/**
* The maximum frequency in which words may still appear. Words that appear
* in more than this many docs will be ignored. Defaults to unbounded.
*/
public int maxDocFreq() {
return this.maxDocFreq;
}
/**
* The minimum word length below which words will be ignored. Defaults to <tt>0</tt>.
*/
public MoreLikeThisRequest minWordLen(int minWordLen) {
this.minWordLen = minWordLen;
return this;
}
/**
* The minimum word length below which words will be ignored. Defaults to <tt>0</tt>.
*/
public int minWordLen() {
return this.minWordLen;
}
/**
* The maximum word length above which words will be ignored. Defaults to unbounded.
*/
public MoreLikeThisRequest maxWordLen(int maxWordLen) {
this.maxWordLen = maxWordLen;
return this;
}
/**
* The maximum word length above which words will be ignored. Defaults to unbounded.
*/
public int maxWordLen() {
return this.maxWordLen;
}
/**
* Whether to boost terms in query based on "score" or not. Defaults to <tt>false</tt>.
*/
public MoreLikeThisRequest boostTerms(Boolean boostTerms) {
this.boostTerms = boostTerms;
return this;
}
/**
* Whether to boost terms in query based on "score" or not. Defaults to <tt>false</tt>.
*/
public Boolean boostTerms() {
return this.boostTerms;
}
/**
* The boost factor to use when boosting terms. Defaults to <tt>1</tt>.
*/
public MoreLikeThisRequest boostTermsFactor(float boostTermsFactor) {
this.boostTermsFactor = boostTermsFactor;
return this;
}
/**
* The boost factor to use when boosting terms. Defaults to <tt>1</tt>.
*/
public float boostTermsFactor() {
return this.boostTermsFactor;
}
/**
* An optional search source request allowing to control the search request for the
* more like this documents.
*/
public MoreLikeThisRequest searchSource(SearchSourceBuilder sourceBuilder) {
return searchSource(sourceBuilder.build());
}
/**
* An optional search source request allowing to control the search request for the
* more like this documents.
*/
public MoreLikeThisRequest searchSource(String searchSource) {
return searchSource(Unicode.fromStringAsBytes(searchSource));
}
/**
* An optional search source request allowing to control the search request for the
* more like this documents.
*/
public MoreLikeThisRequest searchSource(byte[] searchSource) {
this.searchSource = searchSource;
return this;
}
/**
* An optional search source request allowing to control the search request for the
* more like this documents.
*/
public byte[] searchSource() {
return this.searchSource;
}
/**
* Sets the search type of the mlt search query.
* The search type of the mlt search query.
*/
public MoreLikeThisRequest searchType(SearchType searchType) {
this.searchType = searchType;
return this;
}
/**
* The search type of the mlt search query.
*/
public SearchType searchType() {
return this.searchType;
}
/**
* Sets the indices the resulting mlt query will run against. If not set, will run
* The indices the resulting mlt query will run against. If not set, will run
* against the index the document was fetched from.
*/
public MoreLikeThisRequest searchIndices(String... searchIndices) {
@ -230,12 +364,16 @@ public class MoreLikeThisRequest implements ActionRequest {
return this;
}
/**
* The indices the resulting mlt query will run against. If not set, will run
* against the index the document was fetched from.
*/
public String[] searchIndices() {
return this.searchIndices;
}
/**
* Sets the types the resulting mlt query will run against. If not set, will run
* The types the resulting mlt query will run against. If not set, will run
* against the type of the document fetched.
*/
public MoreLikeThisRequest searchTypes(String... searchTypes) {
@ -243,24 +381,42 @@ public class MoreLikeThisRequest implements ActionRequest {
return this;
}
/**
* The types the resulting mlt query will run against. If not set, will run
* against the type of the document fetched.
*/
public String[] searchTypes() {
return this.searchTypes;
}
/**
* Optional search query hint.
*/
public MoreLikeThisRequest searchQueryHint(String searchQueryHint) {
this.searchQueryHint = searchQueryHint;
return this;
}
/**
* Optional search query hint.
*/
public String searchQueryHint() {
return this.searchQueryHint;
}
/**
* An optional search scroll request to be able to continue and scroll the search
* operation.
*/
public MoreLikeThisRequest searchScroll(Scroll searchScroll) {
this.searchScroll = searchScroll;
return this;
}
/**
* An optional search scroll request to be able to continue and scroll the search
* operation.
*/
public Scroll searchScroll() {
return this.searchScroll;
}
@ -279,10 +435,16 @@ public class MoreLikeThisRequest implements ActionRequest {
return validationException;
}
/**
* Should the listener be called on a separate thread if needed.
*/
@Override public boolean listenerThreaded() {
return threadedListener;
}
/**
* Should the listener be called on a separate thread if needed.
*/
@Override public ActionRequest listenerThreaded(boolean listenerThreaded) {
this.threadedListener = listenerThreaded;
return this;

View File

@ -52,6 +52,8 @@ import static org.elasticsearch.index.query.json.JsonQueryBuilders.*;
import static org.elasticsearch.search.builder.SearchSourceBuilder.*;
/**
* The more like this action.
*
* @author kimchy (shay.banon)
*/
public class TransportMoreLikeThisAction extends BaseAction<MoreLikeThisRequest, SearchResponse> {

View File

@ -33,7 +33,7 @@ import java.io.IOException;
*/
public abstract class BroadcastOperationRequest implements ActionRequest {
private String[] indices;
protected String[] indices;
@Nullable protected String queryHint;

View File

@ -31,7 +31,9 @@ import java.util.ArrayList;
import java.util.List;
/**
* @author kimchy (Shay Banon)
* Base class for all broadcast operation based responses.
*
* @author kimchy (shay.banon)
*/
public abstract class BroadcastOperationResponse implements ActionResponse {
@ -53,19 +55,34 @@ public abstract class BroadcastOperationResponse implements ActionResponse {
}
}
/**
* The total shards this request ran against.
*/
public int totalShards() {
return successfulShards + failedShards;
}
/**
* The successful shards this request was executed on.
*/
public int successfulShards() {
return successfulShards;
}
/**
* The failed shards this request was executed on.
*/
public int failedShards() {
return failedShards;
}
/**
* The list of shard failures exception.
*/
public List<? extends ShardOperationFailedException> shardFailures() {
if (shardFailures == null) {
return ImmutableList.of();
}
return shardFailures;
}

View File

@ -25,7 +25,7 @@ import org.elasticsearch.ElasticSearchIllegalArgumentException;
* Controls the operation threading model for broadcast operation that are performed
* locally on the executing node.
*
* @author kimchy (Shay Banon)
* @author kimchy (shay.banon)
*/
public enum BroadcastOperationThreading {
/**

View File

@ -28,7 +28,7 @@ import java.io.DataOutput;
import java.io.IOException;
/**
* @author kimchy (Shay Banon)
* @author kimchy (shay.banon)
*/
public class IndicesReplicationOperationRequest implements ActionRequest {

View File

@ -298,9 +298,28 @@ public interface Client {
*/
void execTerms(TermsRequest request, ActionListener<TermsResponse> listener);
/**
* A more like this action to search for documents that are "like" a specific document.
*
* @param request The more like this request
* @return The response future
*/
ActionFuture<SearchResponse> moreLikeThis(MoreLikeThisRequest request);
/**
* A more like this action to search for documents that are "like" a specific document.
*
* @param request The more like this request
* @param listener A listener to be notified of the result
* @return The response future
*/
ActionFuture<SearchResponse> moreLikeThis(MoreLikeThisRequest request, ActionListener<SearchResponse> listener);
/**
* A more like this action to search for documents that are "like" a specific document.
*
* @param request The more like this request
* @param listener A listener to be notified of the result
*/
void execMoreLikeThis(MoreLikeThisRequest request, ActionListener<SearchResponse> listener);
}

View File

@ -123,8 +123,12 @@ public class Requests {
}
/**
* @param index
* @return
* More like this request represents a request to search for documents that are "like" the provided (fetched)
* document.
*
* @param index The index to load the document from
* @return The more like this request
* @see org.elasticsearch.client.Client#moreLikeThis(org.elasticsearch.action.mlt.MoreLikeThisRequest)
*/
public static MoreLikeThisRequest moreLikeThisRequest(String index) {
return new MoreLikeThisRequest(index);

View File

@ -29,7 +29,12 @@ import java.io.IOException;
import java.util.Date;
/**
* @author kimchy (Shay Banon)
* A helper builder for JSON documents.
*
* <p>Best constructed using {@link #stringJsonBuilder()} or {@link #binaryJsonBuilder()}. When used to create
* source for actions/operations, it is recommended to use {@link #binaryJsonBuilder()}.
*
* @author kimchy (shay.banon)
*/
@NotThreadSafe
public abstract class JsonBuilder<T extends JsonBuilder> {