Browse Source

Term vector API: return 'found: false' for docs between index and refresh

Closes #7121
Alex Ksikes 11 years ago
parent
commit
62ef4a30dc

+ 3 - 1
docs/reference/docs/termvectors.asciidoc

@@ -4,7 +4,9 @@
 added[1.0.0.Beta1]
 
 Returns information and statistics on terms in the fields of a
-particular document as stored in the index.
+particular document as stored in the index. Note that this is a
+near realtime API as the term vectors are not available until the
+next refresh.
 
 [source,js]
 --------------------------------------------------

+ 36 - 0
rest-api-spec/test/termvector/20_issue7121.yaml

@@ -0,0 +1,36 @@
+setup:
+  - do:
+      indices.create:
+          index: testidx
+          body:
+            settings:
+              "index.translog.disable_flush": true
+              "index.number_of_shards": 1
+              "refresh_interval": -1
+            mappings:
+              doc:
+                "properties":
+                  "text":
+                     "type" : "string"
+                     "term_vector" : "with_positions_offsets"
+  - do:
+      index:
+        index: testidx
+        type:  doc
+        id:    1
+        body:
+            "text" : "foo bar"
+
+---
+"Term vector API should return 'found: false' for docs between index and refresh":
+
+  - do:
+      termvector:
+        index: testidx
+        type:  doc
+        id:    1
+
+  - match: { "_index": "testidx" }
+  - match: { "_type": "doc" }
+  - match: { "_id": "1" }
+  - match: { "found": false }

+ 0 - 1
src/main/java/org/elasticsearch/action/termvector/TermVectorResponse.java

@@ -170,7 +170,6 @@ public class TermVectorResponse extends ActionResponse implements ToXContent {
         builder.field(FieldStrings._VERSION, docVersion);
         builder.field(FieldStrings.FOUND, isExists());
         if (!isExists()) {
-            builder.endObject();
             return builder;
         }
         builder.startObject(FieldStrings.TERM_VECTORS);

+ 3 - 0
src/test/java/org/elasticsearch/action/termvector/GetTermVectorTests.java

@@ -29,6 +29,7 @@ import org.elasticsearch.action.ActionFuture;
 import org.elasticsearch.action.admin.indices.alias.Alias;
 import org.elasticsearch.action.index.IndexRequestBuilder;
 import org.elasticsearch.common.settings.ImmutableSettings;
+import org.elasticsearch.common.xcontent.ToXContent;
 import org.elasticsearch.common.xcontent.XContentBuilder;
 import org.elasticsearch.common.xcontent.XContentFactory;
 import org.elasticsearch.index.mapper.core.AbstractFieldMapper;
@@ -70,6 +71,8 @@ public class GetTermVectorTests extends AbstractTermVectorTests {
             assertThat(actionGet, notNullValue());
             assertThat(actionGet.getIndex(), equalTo("test"));
             assertThat(actionGet.isExists(), equalTo(false));
+            // check response is nevertheless serializable to json
+            actionGet.toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS);
         }
     }