Term Vectors: Fix NPE with dfs and no tvs

Fixes a bug with dfs option for when term vectors are not stored and not generated.
This commit is contained in:
Alex Ksikes 2014-11-13 08:22:03 +01:00
parent 9956e7721d
commit 936b4c63fc
2 changed files with 8 additions and 7 deletions

View File

@ -107,7 +107,7 @@ public class ShardTermVectorService extends AbstractIndexShardComponent {
if (topLevelFields == null) {
topLevelFields = termVectorsByField;
}
if (useDfs(request)) {
if (termVectorsByField != null && useDfs(request)) {
dfs = getAggregatedDfs(termVectorsByField, request);
}
termVectorResponse.setFields(termVectorsByField, request.selectedFields(), request.getFlags(), topLevelFields, dfs);
@ -127,7 +127,7 @@ public class ShardTermVectorService extends AbstractIndexShardComponent {
if (selectedFields != null) {
termVectorsByField = addGeneratedTermVectors(get, termVectorsByField, request, selectedFields);
}
if (useDfs(request)) {
if (termVectorsByField != null && useDfs(request)) {
dfs = getAggregatedDfs(termVectorsByField, request);
}
termVectorResponse.setFields(termVectorsByField, request.selectedFields(), request.getFlags(), topLevelFields, dfs);

View File

@ -90,8 +90,7 @@ public class GetTermVectorTests extends AbstractTermVectorTests {
ensureYellow();
// when indexing a field that simply has a question mark, the term
// vectors will be null
// when indexing a field that simply has a question mark, the term vectors will be null
client().prepareIndex("test", "type1", "0").setSource("existingfield", "?").execute().actionGet();
refresh();
ActionFuture<TermVectorResponse> termVector = client().termVector(new TermVectorRequest(indexOrAlias(), "type1", "0")
@ -119,12 +118,14 @@ public class GetTermVectorTests extends AbstractTermVectorTests {
ensureYellow();
// when indexing a field that simply has a question mark, the term
// vectors will be null
// when indexing a field that simply has a question mark, the term vectors will be null
client().prepareIndex("test", "type1", "0").setSource("anotherexistingfield", 1).execute().actionGet();
refresh();
ActionFuture<TermVectorResponse> termVector = client().termVector(new TermVectorRequest(indexOrAlias(), "type1", "0")
.selectedFields(new String[]{"existingfield"}));
.selectedFields(randomBoolean() ? new String[]{"existingfield"} : null)
.termStatistics(true)
.fieldStatistics(true)
.dfs(true));
// lets see if the null term vectors are caught...
TermVectorResponse actionGet = termVector.actionGet();