Skip to content

Commit

Permalink
Term Vectors: More consistent naming for term vector[s]
Browse files Browse the repository at this point in the history
We speak of the term vectors of a document, where each field has an associated
stored term vector. Since by default we are requesting all the term vectors of
a document, the HTTP request endpoint should rather be called `_termvectors`
instead of `_termvector`. The usage of `_termvector` is now deprecated, as
well as the transport client call to termVector and prepareTermVector.

Closes #8484
  • Loading branch information
alexksikes committed Nov 21, 2014
1 parent a6e6c4e commit 1959275
Show file tree
Hide file tree
Showing 57 changed files with 484 additions and 420 deletions.
15 changes: 9 additions & 6 deletions docs/reference/docs/termvectors.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,24 @@ realtime. This can be changed by setting `realtime` parameter to `false`.

[source,js]
--------------------------------------------------
curl -XGET 'http://localhost:9200/twitter/tweet/1/_termvector?pretty=true'
curl -XGET 'http://localhost:9200/twitter/tweet/1/_termvectors?pretty=true'
--------------------------------------------------

Optionally, you can specify the fields for which the information is
retrieved either with a parameter in the url

[source,js]
--------------------------------------------------
curl -XGET 'http://localhost:9200/twitter/tweet/1/_termvector?fields=text,...'
curl -XGET 'http://localhost:9200/twitter/tweet/1/_termvectors?fields=text,...'
--------------------------------------------------

or by adding the requested fields in the request body (see
example below). Fields can also be specified with wildcards
in similar way to the <<query-dsl-multi-match-query,multi match query>>

[WARNING]
Note that the usage of `/_termvector` is deprecated in 2.0, and replaced by `/_termvectors`.

[float]
=== Return values

Expand Down Expand Up @@ -160,7 +163,7 @@ The following request returns all information and statistics for field
[source,js]
--------------------------------------------------
curl -XGET 'http://localhost:9200/twitter/tweet/1/_termvector?pretty=true' -d '{
curl -XGET 'http://localhost:9200/twitter/tweet/1/_termvectors?pretty=true' -d '{
"fields" : ["text"],
"offsets" : true,
"payloads" : true,
Expand Down Expand Up @@ -243,7 +246,7 @@ Note that for the field `text`, the terms are not re-generated.

[source,js]
--------------------------------------------------
curl -XGET 'http://localhost:9200/twitter/tweet/1/_termvector?pretty=true' -d '{
curl -XGET 'http://localhost:9200/twitter/tweet/1/_termvectors?pretty=true' -d '{
"fields" : ["text", "some_field_without_term_vectors"],
"offsets" : true,
"positions" : true,
Expand All @@ -270,7 +273,7 @@ mapping will be dynamically created.

[source,js]
--------------------------------------------------
curl -XGET 'http://localhost:9200/twitter/tweet/_termvector' -d '{
curl -XGET 'http://localhost:9200/twitter/tweet/_termvectors' -d '{
"doc" : {
"fullname" : "John Doe",
"text" : "twitter test test test"
Expand All @@ -290,7 +293,7 @@ vectors, the term vectors will be re-generated.

[source,js]
--------------------------------------------------
curl -XGET 'http://localhost:9200/twitter/tweet/_termvector' -d '{
curl -XGET 'http://localhost:9200/twitter/tweet/_termvectors' -d '{
"doc" : {
"fullname" : "John Doe",
"text" : "twitter test test test"
Expand Down
4 changes: 4 additions & 0 deletions docs/reference/migration/migrate_2_0.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ In addition, the following node settings related to routing have been deprecated
=== Store

The `memory` / `ram` store (`index.store.type`) option was removed in Elasticsearch 2.0.

=== Term Vectors API

Usage of `/_termvector` is deprecated, and replaced in favor of `/_termvectors`.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"termvector" : {
"termvectors" : {
"documentation" : "http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/docs-termvectors.html",
"methods" : ["GET", "POST"],
"url" : {
"path" : "/{index}/{type}/{id}/_termvector",
"paths" : ["/{index}/{type}/{id}/_termvector"],
"path" : "/{index}/{type}/{id}/_termvectors",
"paths" : ["/{index}/{type}/{id}/_termvectors"],
"parts" : {
"index" : {
"type" : "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ setup:
"Basic tests for termvector get":

- do:
termvector:
termvectors:
index: testidx
type: testtype
id: testing_document
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
text : "foo bar"

- do:
termvector:
termvectors:
index: testidx
type: doc
id: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
body: { foo: bar }

- do:
termvector:
termvectors:
index: test_1
type: test
id: 1
Expand All @@ -31,7 +31,7 @@
- is_false: found

- do:
termvector:
termvectors:
index: test_1
type: test
id: 1
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/elasticsearch/action/ActionModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@
import org.elasticsearch.action.support.ActionFilter;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.action.termvector.*;
import org.elasticsearch.action.termvector.dfs.TransportDfsOnlyAction;
import org.elasticsearch.action.termvectors.*;
import org.elasticsearch.action.termvectors.dfs.TransportDfsOnlyAction;
import org.elasticsearch.action.update.TransportUpdateAction;
import org.elasticsearch.action.update.UpdateAction;
import org.elasticsearch.common.inject.AbstractModule;
Expand Down Expand Up @@ -281,10 +281,10 @@ protected void configure() {

registerAction(IndexAction.INSTANCE, TransportIndexAction.class);
registerAction(GetAction.INSTANCE, TransportGetAction.class);
registerAction(TermVectorAction.INSTANCE, TransportSingleShardTermVectorAction.class,
registerAction(TermVectorsAction.INSTANCE, TransportTermVectorsAction.class,
TransportDfsOnlyAction.class);
registerAction(MultiTermVectorsAction.INSTANCE, TransportMultiTermVectorsAction.class,
TransportSingleShardMultiTermsVectorAction.class);
TransportShardMultiTermsVectorAction.class);
registerAction(DeleteAction.INSTANCE, TransportDeleteAction.class,
TransportIndexDeleteAction.class, TransportShardDeleteAction.class);
registerAction(CountAction.INSTANCE, TransportCountAction.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package org.elasticsearch.action.termvector;
package org.elasticsearch.action.termvectors;

import org.elasticsearch.action.ClientAction;
import org.elasticsearch.client.Client;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package org.elasticsearch.action.termvector;
package org.elasticsearch.action.termvectors;

import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
Expand All @@ -30,14 +30,14 @@
*/
public class MultiTermVectorsItemResponse implements Streamable {

private TermVectorResponse response;
private TermVectorsResponse response;
private MultiTermVectorsResponse.Failure failure;

MultiTermVectorsItemResponse() {

}

public MultiTermVectorsItemResponse(TermVectorResponse response, MultiTermVectorsResponse.Failure failure) {
public MultiTermVectorsItemResponse(TermVectorsResponse response, MultiTermVectorsResponse.Failure failure) {
assert (((response == null) && (failure != null)) || ((response != null) && (failure == null)));
this.response = response;
this.failure = failure;
Expand Down Expand Up @@ -83,7 +83,7 @@ public boolean isFailed() {
/**
* The actual get response, <tt>null</tt> if its a failure.
*/
public TermVectorResponse getResponse() {
public TermVectorsResponse getResponse() {
return this.response;
}

Expand All @@ -105,7 +105,7 @@ public void readFrom(StreamInput in) throws IOException {
if (in.readBoolean()) {
failure = MultiTermVectorsResponse.Failure.readFailure(in);
} else {
response = new TermVectorResponse();
response = new TermVectorsResponse();
response.readFrom(in);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package org.elasticsearch.action.termvector;
package org.elasticsearch.action.termvectors;

import com.google.common.collect.Iterators;
import org.elasticsearch.ElasticsearchIllegalArgumentException;
Expand All @@ -33,20 +33,20 @@
import java.io.IOException;
import java.util.*;

public class MultiTermVectorsRequest extends ActionRequest<MultiTermVectorsRequest> implements Iterable<TermVectorRequest>, CompositeIndicesRequest {
public class MultiTermVectorsRequest extends ActionRequest<MultiTermVectorsRequest> implements Iterable<TermVectorsRequest>, CompositeIndicesRequest {

String preference;
List<TermVectorRequest> requests = new ArrayList<>();
List<TermVectorsRequest> requests = new ArrayList<>();

final Set<String> ids = new HashSet<>();

public MultiTermVectorsRequest add(TermVectorRequest termVectorRequest) {
requests.add(termVectorRequest);
public MultiTermVectorsRequest add(TermVectorsRequest termVectorsRequest) {
requests.add(termVectorsRequest);
return this;
}

public MultiTermVectorsRequest add(String index, @Nullable String type, String id) {
requests.add(new TermVectorRequest(index, type, id));
requests.add(new TermVectorsRequest(index, type, id));
return this;
}

Expand All @@ -57,8 +57,8 @@ public ActionRequestValidationException validate() {
validationException = ValidateActions.addValidationError("multi term vectors: no documents requested", validationException);
} else {
for (int i = 0; i < requests.size(); i++) {
TermVectorRequest termVectorRequest = requests.get(i);
ActionRequestValidationException validationExceptionForDoc = termVectorRequest.validate();
TermVectorsRequest termVectorsRequest = requests.get(i);
ActionRequestValidationException validationExceptionForDoc = termVectorsRequest.validate();
if (validationExceptionForDoc != null) {
validationException = ValidateActions.addValidationError("at multi term vectors for doc " + i,
validationExceptionForDoc);
Expand All @@ -74,19 +74,19 @@ public List<? extends IndicesRequest> subRequests() {
}

@Override
public Iterator<TermVectorRequest> iterator() {
public Iterator<TermVectorsRequest> iterator() {
return Iterators.unmodifiableIterator(requests.iterator());
}

public boolean isEmpty() {
return requests.isEmpty() && ids.isEmpty();
}

public List<TermVectorRequest> getRequests() {
public List<TermVectorsRequest> getRequests() {
return requests;
}

public void add(TermVectorRequest template, BytesReference data) throws Exception {
public void add(TermVectorsRequest template, BytesReference data) throws Exception {
XContentParser.Token token;
String currentFieldName = null;
if (data.length() > 0) {
Expand All @@ -100,9 +100,9 @@ public void add(TermVectorRequest template, BytesReference data) throws Exceptio
if (token != XContentParser.Token.START_OBJECT) {
throw new ElasticsearchIllegalArgumentException("docs array element should include an object");
}
TermVectorRequest termVectorRequest = new TermVectorRequest(template);
TermVectorRequest.parseRequest(termVectorRequest, parser);
add(termVectorRequest);
TermVectorsRequest termVectorsRequest = new TermVectorsRequest(template);
TermVectorsRequest.parseRequest(termVectorsRequest, parser);
add(termVectorsRequest);
}
} else if ("ids".equals(currentFieldName)) {
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
Expand All @@ -117,7 +117,7 @@ public void add(TermVectorRequest template, BytesReference data) throws Exceptio
}
} else if (token == XContentParser.Token.START_OBJECT && currentFieldName != null) {
if ("parameters".equals(currentFieldName)) {
TermVectorRequest.parseRequest(template, parser);
TermVectorsRequest.parseRequest(template, parser);
} else {
throw new ElasticsearchParseException(
"No parameter named " + currentFieldName + "and type OBJECT");
Expand All @@ -129,7 +129,7 @@ public void add(TermVectorRequest template, BytesReference data) throws Exceptio
}
}
for (String id : ids) {
TermVectorRequest curRequest = new TermVectorRequest(template);
TermVectorsRequest curRequest = new TermVectorsRequest(template);
curRequest.id(id);
requests.add(curRequest);
}
Expand All @@ -142,7 +142,7 @@ public void readFrom(StreamInput in) throws IOException {
int size = in.readVInt();
requests = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
requests.add(TermVectorRequest.readTermVectorRequest(in));
requests.add(TermVectorsRequest.readTermVectorsRequest(in));
}
}

Expand All @@ -151,8 +151,8 @@ public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeOptionalString(preference);
out.writeVInt(requests.size());
for (TermVectorRequest termVectorRequest : requests) {
termVectorRequest.writeTo(out);
for (TermVectorsRequest termVectorsRequest : requests) {
termVectorsRequest.writeTo(out);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package org.elasticsearch.action.termvector;
package org.elasticsearch.action.termvectors;

import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRequestBuilder;
Expand All @@ -43,8 +43,8 @@ public MultiTermVectorsRequestBuilder add(String index, @Nullable String type, S
return this;
}

public MultiTermVectorsRequestBuilder add(TermVectorRequest termVectorRequest) {
request.add(termVectorRequest);
public MultiTermVectorsRequestBuilder add(TermVectorsRequest termVectorsRequest) {
request.add(termVectorsRequest);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package org.elasticsearch.action.termvector;
package org.elasticsearch.action.termvectors;

import com.google.common.collect.Iterators;
import org.elasticsearch.action.ActionResponse;
Expand Down Expand Up @@ -135,7 +135,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.field(Fields.ERROR, failure.getMessage());
builder.endObject();
} else {
TermVectorResponse getResponse = response.getResponse();
TermVectorsResponse getResponse = response.getResponse();
builder.startObject();
getResponse.toXContent(builder, params);
builder.endObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package org.elasticsearch.action.termvector;
package org.elasticsearch.action.termvectors;

import com.carrotsearch.hppc.IntArrayList;
import org.elasticsearch.action.support.single.shard.SingleShardOperationRequest;
Expand All @@ -34,7 +34,7 @@ public class MultiTermVectorsShardRequest extends SingleShardOperationRequest<Mu
private String preference;

IntArrayList locations;
List<TermVectorRequest> requests;
List<TermVectorsRequest> requests;

MultiTermVectorsShardRequest() {

Expand Down Expand Up @@ -66,7 +66,7 @@ public String preference() {
}


public void add(int location, TermVectorRequest request) {
public void add(int location, TermVectorsRequest request) {
this.locations.add(location);
this.requests.add(request);
}
Expand All @@ -88,7 +88,7 @@ public void readFrom(StreamInput in) throws IOException {
requests = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
locations.add(in.readVInt());
requests.add(TermVectorRequest.readTermVectorRequest(in));
requests.add(TermVectorsRequest.readTermVectorsRequest(in));
}

preference = in.readOptionalString();
Expand Down

0 comments on commit 1959275

Please sign in to comment.