Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow MappedFieldType impls to hide themselves from field caps #63547

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 }
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> meta) {
public IndexFieldCapabilities(String name, String type,
boolean isSearchable, boolean isAggregatable,
Map<String, String> meta) {

this.name = name;
this.type = type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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();
Expand Down