diff --git a/docs/reference/docs/termvectors.asciidoc b/docs/reference/docs/termvectors.asciidoc index 7a19c2ead23..fabd014bafd 100644 --- a/docs/reference/docs/termvectors.asciidoc +++ b/docs/reference/docs/termvectors.asciidoc @@ -20,7 +20,8 @@ curl -XGET 'http://localhost:9200/twitter/tweet/1/_termvector?fields=text,...' -------------------------------------------------- or by adding the requested fields in the request body (see -example below). +example below). Fields can also be specified with wildcards +in similar way to the <> added[1.4.0]. [float] === Return values diff --git a/src/main/java/org/elasticsearch/action/termvector/MultiTermVectorsRequest.java b/src/main/java/org/elasticsearch/action/termvector/MultiTermVectorsRequest.java index cf048bd5af5..d2a0467d47e 100644 --- a/src/main/java/org/elasticsearch/action/termvector/MultiTermVectorsRequest.java +++ b/src/main/java/org/elasticsearch/action/termvector/MultiTermVectorsRequest.java @@ -75,9 +75,7 @@ public class MultiTermVectorsRequest extends ActionRequest 0) { diff --git a/src/main/java/org/elasticsearch/action/termvector/TermVectorRequest.java b/src/main/java/org/elasticsearch/action/termvector/TermVectorRequest.java index ce46d1b6e18..577458d9bef 100644 --- a/src/main/java/org/elasticsearch/action/termvector/TermVectorRequest.java +++ b/src/main/java/org/elasticsearch/action/termvector/TermVectorRequest.java @@ -358,7 +358,6 @@ public class TermVectorRequest extends SingleShardOperationRequest fieldNames = new HashSet<>(); + for (String pattern : request.selectedFields()) { + fieldNames.addAll(indexShard.mapperService().simpleMatchToIndexNames(pattern)); + } + request.selectedFields(fieldNames.toArray(Strings.EMPTY_ARRAY)); + } + private Fields generateTermVectorsIfNeeded(Fields termVectorsByField, TermVectorRequest request, Term uidTerm, boolean realTime) throws IOException { List validFields = new ArrayList<>(); for (String field : request.selectedFields()) { @@ -187,4 +200,5 @@ public class ShardTermVectorService extends AbstractIndexShardComponent { return fields.size(); } } + } diff --git a/src/test/java/org/elasticsearch/action/termvector/GetTermVectorTests.java b/src/test/java/org/elasticsearch/action/termvector/GetTermVectorTests.java index 653ce09a950..38c0489bc78 100644 --- a/src/test/java/org/elasticsearch/action/termvector/GetTermVectorTests.java +++ b/src/test/java/org/elasticsearch/action/termvector/GetTermVectorTests.java @@ -740,4 +740,31 @@ public class GetTermVectorTests extends AbstractTermVectorTests { assertThat(iter0.next(), nullValue()); assertThat(iter1.next(), nullValue()); } + + @Test + public void testSimpleWildCards() throws ElasticsearchException, IOException { + int numFields = 25; + + XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties"); + XContentBuilder source = XContentFactory.jsonBuilder().startObject(); + for (int i = 0; i < numFields; i++) { + mapping.startObject("field" + i) + .field("type", "string") + .field("term_vector", randomBoolean() ? "yes" : "no") + .endObject(); + source.field("field" + i, "some text here"); + } + source.endObject(); + mapping.endObject().endObject().endObject(); + + assertAcked(prepareCreate("test").addMapping("type1", mapping)); + ensureGreen(); + + client().prepareIndex("test", "type1", "0").setSource(source).get(); + refresh(); + + TermVectorResponse response = client().prepareTermVector("test", "type1", "0").setSelectedFields("field*").get(); + assertThat("Doc doesn't exists but should", response.isExists(), equalTo(true)); + assertThat("All term vectors should have been generated", response.getFields().size(), equalTo(numFields)); + } }