Provide meaningful error message if field has no fielddata type
closes #5930
This commit is contained in:
parent
d07c5a5c32
commit
9d214d14fe
|
@ -207,6 +207,9 @@ public class IndexFieldDataService extends AbstractIndexComponent {
|
|||
public <IFD extends IndexFieldData<?>> IFD getForField(FieldMapper<?> mapper) {
|
||||
final FieldMapper.Names fieldNames = mapper.names();
|
||||
final FieldDataType type = mapper.fieldDataType();
|
||||
if (type == null) {
|
||||
throw new ElasticsearchIllegalArgumentException("found no fielddata type for field [" + fieldNames.fullName() + "]");
|
||||
}
|
||||
final boolean docValues = mapper.hasDocValues();
|
||||
IndexFieldData<?> fieldData = loadedFieldData.get(fieldNames.indexName());
|
||||
if (fieldData == null) {
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
|
|||
import org.elasticsearch.action.index.IndexRequestBuilder;
|
||||
import org.elasticsearch.action.percolate.PercolateResponse;
|
||||
import org.elasticsearch.action.search.SearchPhaseExecutionException;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.suggest.SuggestResponse;
|
||||
import org.elasticsearch.client.Requests;
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
|
@ -40,6 +41,7 @@ import org.elasticsearch.index.mapper.MapperException;
|
|||
import org.elasticsearch.index.mapper.MapperParsingException;
|
||||
import org.elasticsearch.index.mapper.core.CompletionFieldMapper;
|
||||
import org.elasticsearch.percolator.PercolatorService;
|
||||
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
||||
import org.elasticsearch.search.sort.FieldSortBuilder;
|
||||
import org.elasticsearch.search.suggest.completion.CompletionStats;
|
||||
import org.elasticsearch.search.suggest.completion.CompletionSuggestion;
|
||||
|
@ -1062,6 +1064,33 @@ public class CompletionSuggestSearchTests extends ElasticsearchIntegrationTest {
|
|||
).setRefresh(true).get();
|
||||
}
|
||||
|
||||
@Test // see #5930
|
||||
public void testIssue5930() throws IOException {
|
||||
client().admin().indices().prepareCreate(INDEX).get();
|
||||
ElasticsearchAssertions.assertAcked(client().admin().indices().preparePutMapping(INDEX).setType(TYPE).setSource(jsonBuilder().startObject()
|
||||
.startObject(TYPE).startObject("properties")
|
||||
.startObject(FIELD)
|
||||
.field("type", "completion")
|
||||
.endObject()
|
||||
.endObject().endObject()
|
||||
.endObject()));
|
||||
ensureYellow();
|
||||
String string = "foo bar";
|
||||
client().prepareIndex(INDEX, TYPE, "1").setSource(jsonBuilder()
|
||||
.startObject()
|
||||
.field(FIELD, string)
|
||||
.endObject()
|
||||
).setRefresh(true).get();
|
||||
|
||||
try {
|
||||
client().prepareSearch(INDEX).addAggregation(AggregationBuilders.terms("suggest_agg").field(FIELD)).execute().actionGet();
|
||||
// Exception must be thrown
|
||||
assertFalse(true);
|
||||
} catch (SearchPhaseExecutionException e) {
|
||||
assertTrue(e.getDetailedMessage().contains("found no fielddata type for field [" + FIELD + "]"));
|
||||
}
|
||||
}
|
||||
|
||||
private static String replaceReservedChars(String input, char replacement) {
|
||||
char[] charArray = input.toCharArray();
|
||||
for (int i = 0; i < charArray.length; i++) {
|
||||
|
|
Loading…
Reference in New Issue