diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/field_caps/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/field_caps/10_basic.yml index 87134e3e18d9d..ec07123e4653a 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/field_caps/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/field_caps/10_basic.yml @@ -8,6 +8,12 @@ setup: properties: text: type: text + text_with_subs: + type: text + index_prefixes: + min_chars: 2 + max_chars: 3 + index_phrases: true keyword: type: keyword number: @@ -316,3 +322,18 @@ setup: - match: {fields.misc.unmapped.searchable: false} - match: {fields.misc.unmapped.aggregatable: false} - match: {fields.misc.unmapped.indices: ["test2", "test3"]} + +--- +"Field caps exclude text implementation subfields": + - skip: + version: " - 8.0.0" + reason: subfields excluded in 7.11 + + - do: + field_caps: + index: 'test1,test2,test3' + fields: [ text_with_subs ] + + - match: { fields.text_with_subs: true } + - match: { fields.text_with_subs._index_prefix: false } + - match: { fields.text_with_subs._index_phrase: false } diff --git a/server/src/main/java/org/elasticsearch/action/fieldcaps/IndexFieldCapabilities.java b/server/src/main/java/org/elasticsearch/action/fieldcaps/IndexFieldCapabilities.java index 7948e6dd8b516..158c9d9ac3232 100644 --- a/server/src/main/java/org/elasticsearch/action/fieldcaps/IndexFieldCapabilities.java +++ b/server/src/main/java/org/elasticsearch/action/fieldcaps/IndexFieldCapabilities.java @@ -48,9 +48,9 @@ public class IndexFieldCapabilities implements Writeable { * @param isAggregatable Whether this field can be aggregated on. * @param meta Metadata about the field. */ - IndexFieldCapabilities(String name, String type, - boolean isSearchable, boolean isAggregatable, - Map meta) { + public IndexFieldCapabilities(String name, String type, + boolean isSearchable, boolean isAggregatable, + Map meta) { this.name = name; this.type = type; diff --git a/server/src/main/java/org/elasticsearch/action/fieldcaps/TransportFieldCapabilitiesIndexAction.java b/server/src/main/java/org/elasticsearch/action/fieldcaps/TransportFieldCapabilitiesIndexAction.java index b508e5648bdc7..a9ba61b402a2e 100644 --- a/server/src/main/java/org/elasticsearch/action/fieldcaps/TransportFieldCapabilitiesIndexAction.java +++ b/server/src/main/java/org/elasticsearch/action/fieldcaps/TransportFieldCapabilitiesIndexAction.java @@ -124,8 +124,10 @@ private FieldCapabilitiesIndexResponse shardOperation(final FieldCapabilitiesInd if (ft != null) { if (indicesService.isMetadataField(mapperService.getIndexSettings().getIndexVersionCreated(), field) || fieldPredicate.test(ft.name())) { - IndexFieldCapabilities fieldCap = new IndexFieldCapabilities(field, ft.familyTypeName(), - ft.isSearchable(), ft.isAggregatable(), ft.meta()); + IndexFieldCapabilities fieldCap = ft.fieldCaps(); + if (fieldCap == null) { + continue; + } responseMap.put(field, fieldCap); } else { continue; diff --git a/server/src/main/java/org/elasticsearch/index/mapper/MappedFieldType.java b/server/src/main/java/org/elasticsearch/index/mapper/MappedFieldType.java index 60574cd3017f4..17a3f0df31f1c 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/MappedFieldType.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/MappedFieldType.java @@ -39,6 +39,7 @@ import org.apache.lucene.search.spans.SpanQuery; import org.apache.lucene.util.BytesRef; import org.elasticsearch.ElasticsearchParseException; +import org.elasticsearch.action.fieldcaps.IndexFieldCapabilities; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.geo.ShapeRelation; import org.elasticsearch.common.time.DateMathParser; @@ -111,6 +112,16 @@ public String familyTypeName() { return typeName(); } + /** + * Returns the capabilities of this field. + * + * If the field should not be returned as part of a Field Capabilities call, + * implementations can return {@code null} + */ + public IndexFieldCapabilities fieldCaps() { + return new IndexFieldCapabilities(name, familyTypeName(), isSearchable(), isAggregatable(), meta); + } + public String name() { return name; } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java index cd664cc05bcee..89987462a7c65 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java @@ -57,6 +57,7 @@ import org.apache.lucene.util.automaton.Automaton; import org.apache.lucene.util.automaton.Operations; import org.elasticsearch.Version; +import org.elasticsearch.action.fieldcaps.IndexFieldCapabilities; import org.elasticsearch.common.collect.Iterators; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.lucene.search.AutomatonQueries; @@ -459,6 +460,11 @@ void setAnalyzer(String name, Analyzer delegate) { setIndexAnalyzer(new NamedAnalyzer(name, AnalyzerScope.INDEX, new PhraseWrappedAnalyzer(delegate))); } + @Override + public IndexFieldCapabilities fieldCaps() { + return null; // don't show impl sub-fields in fieldcaps + } + @Override public String typeName() { return "phrase"; @@ -492,6 +498,11 @@ static final class PrefixFieldType extends StringFieldType { this.parentField = parentField; } + @Override + public IndexFieldCapabilities fieldCaps() { + return null; // don't show impl subfields in field caps + } + @Override public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searchLookup, String format) { throw new UnsupportedOperationException();