|
30 | 30 | import org.elasticsearch.tasks.CancellableTask; |
31 | 31 |
|
32 | 32 | import java.io.IOException; |
33 | | -import java.util.Arrays; |
34 | 33 | import java.util.Collections; |
35 | 34 | import java.util.HashMap; |
36 | 35 | import java.util.Map; |
@@ -159,9 +158,11 @@ static Map<String, IndexFieldCapabilities> retrieveFieldCaps( |
159 | 158 | IndexShard indexShard, |
160 | 159 | boolean includeEmptyFields |
161 | 160 | ) { |
162 | | - boolean includeParentObjects = checkIncludeParents(filters); |
| 161 | + Set<String> appliedFilters = Set.of(filters); |
| 162 | + boolean includeParentObjects = appliedFilters.contains("-parent") == false; |
163 | 163 |
|
164 | | - Predicate<MappedFieldType> filter = buildFilter(filters, types, context); |
| 164 | + Set<String> acceptedTypes = Set.of(types); |
| 165 | + Predicate<MappedFieldType> filter = buildFilter(filters, acceptedTypes, context); |
165 | 166 | boolean isTimeSeriesIndex = context.getIndexSettings().getTimestampBounds() != null; |
166 | 167 | var fieldInfos = indexShard.getFieldInfos(); |
167 | 168 | includeEmptyFields = includeEmptyFields || enableFieldHasValue == false; |
@@ -205,18 +206,17 @@ static Map<String, IndexFieldCapabilities> retrieveFieldCaps( |
205 | 206 | if (context.getFieldType(parentField) == null) { |
206 | 207 | // no field type, it must be an object field |
207 | 208 | String type = context.nestedLookup().getNestedMappers().get(parentField) != null ? "nested" : "object"; |
208 | | - IndexFieldCapabilities fieldCap = new IndexFieldCapabilities( |
209 | | - parentField, |
210 | | - type, |
211 | | - false, |
212 | | - false, |
213 | | - false, |
214 | | - false, |
215 | | - null, |
216 | | - Map.of() |
217 | | - ); |
218 | | - |
219 | | - if (filter == null || Arrays.asList(types).contains(type)) { |
| 209 | + if (filter == null || acceptedTypes.contains(type) || appliedFilters.contains("parent")) { |
| 210 | + IndexFieldCapabilities fieldCap = new IndexFieldCapabilities( |
| 211 | + parentField, |
| 212 | + type, |
| 213 | + false, |
| 214 | + false, |
| 215 | + false, |
| 216 | + false, |
| 217 | + null, |
| 218 | + Map.of() |
| 219 | + ); |
220 | 220 | responseMap.put(parentField, fieldCap); |
221 | 221 | } |
222 | 222 | } |
@@ -253,12 +253,11 @@ private static boolean alwaysMatches(QueryBuilder indexFilter) { |
253 | 253 | return indexFilter == null || indexFilter instanceof MatchAllQueryBuilder; |
254 | 254 | } |
255 | 255 |
|
256 | | - private static Predicate<MappedFieldType> buildFilter(String[] filters, String[] fieldTypes, SearchExecutionContext context) { |
| 256 | + private static Predicate<MappedFieldType> buildFilter(String[] filters, Set<String> fieldTypes, SearchExecutionContext context) { |
257 | 257 | // security filters don't exclude metadata fields |
258 | 258 | Predicate<MappedFieldType> fcf = null; |
259 | | - if (fieldTypes.length > 0) { |
260 | | - Set<String> acceptedTypes = Set.of(fieldTypes); |
261 | | - fcf = ft -> acceptedTypes.contains(ft.familyTypeName()); |
| 259 | + if (fieldTypes.isEmpty() == false) { |
| 260 | + fcf = ft -> fieldTypes.contains(ft.familyTypeName()); |
262 | 261 | } |
263 | 262 | for (String filter : filters) { |
264 | 263 | if ("parent".equals(filter) || "-parent".equals(filter)) { |
|
0 commit comments