field stats: Fix NPE when index constraint has been set on mapped field but the index is empty
This commit is contained in:
parent
3cacec4468
commit
1661ce5b8c
|
@ -119,6 +119,10 @@ public class TransportFieldStatsTransportAction extends TransportBroadcastAction
|
|||
while (iterator.hasNext()) {
|
||||
Map.Entry<String, Map<String, FieldStats>> entry = iterator.next();
|
||||
FieldStats indexConstraintFieldStats = entry.getValue().get(indexConstraint.getField());
|
||||
if (indexConstraintFieldStats == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (indexConstraintFieldStats.match(indexConstraint)) {
|
||||
// If the field stats didn't occur in the list of fields in the original request we need to remove the
|
||||
// field stats, because it was never requested and was only needed to validate the index constraint
|
||||
|
|
|
@ -390,4 +390,22 @@ public class FieldStatsTests extends ESSingleNodeTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public void testEmptyIndex() {
|
||||
createIndex("test1", Settings.EMPTY, "type", "value", "type=date");
|
||||
FieldStatsResponse response = client().prepareFieldStats()
|
||||
.setFields("value")
|
||||
.setLevel("indices")
|
||||
.get();
|
||||
assertThat(response.getIndicesMergedFieldStats().size(), equalTo(1));
|
||||
assertThat(response.getIndicesMergedFieldStats().get("test1").size(), equalTo(0));
|
||||
|
||||
response = client().prepareFieldStats()
|
||||
.setFields("value")
|
||||
.setIndexContraints(new IndexConstraint("value", MIN, GTE, "1998-01-01T00:00:00.000Z"))
|
||||
.setLevel("indices")
|
||||
.get();
|
||||
assertThat(response.getIndicesMergedFieldStats().size(), equalTo(1));
|
||||
assertThat(response.getIndicesMergedFieldStats().get("test1").size(), equalTo(0));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue