-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Make FieldNamesFieldMapper responsible for adding its own doc fields #71929
Changes from 3 commits
0c509b4
b589ee4
449597f
2785d95
95df369
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
|
||
package org.elasticsearch.index.mapper; | ||
|
||
import org.apache.lucene.document.Field; | ||
import org.apache.lucene.document.FieldType; | ||
import org.apache.lucene.index.IndexOptions; | ||
import org.apache.lucene.search.Query; | ||
|
@@ -17,8 +18,8 @@ | |
import org.elasticsearch.common.logging.DeprecationLogger; | ||
import org.elasticsearch.index.query.SearchExecutionContext; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
/** | ||
|
@@ -155,40 +156,14 @@ public FieldNamesFieldType fieldType() { | |
return (FieldNamesFieldType) super.fieldType(); | ||
} | ||
|
||
static Iterable<String> extractFieldNames(final String fullPath) { | ||
return new Iterable<String>() { | ||
@Override | ||
public Iterator<String> iterator() { | ||
return new Iterator<>() { | ||
int endIndex = nextEndIndex(0); | ||
|
||
private int nextEndIndex(int index) { | ||
while (index < fullPath.length() && fullPath.charAt(index) != '.') { | ||
index += 1; | ||
} | ||
return index; | ||
} | ||
|
||
@Override | ||
public boolean hasNext() { | ||
return endIndex <= fullPath.length(); | ||
} | ||
|
||
@Override | ||
public String next() { | ||
final String result = fullPath.substring(0, endIndex); | ||
endIndex = nextEndIndex(endIndex + 1); | ||
return result; | ||
} | ||
|
||
@Override | ||
public void remove() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
}; | ||
} | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. on simplifying this and not indexing all the inner paths, that makes sense, but should we make that change in a separate PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good point, I'll pull this change into a separate issue. |
||
@Override | ||
public void postParse(ParseContext context) throws IOException { | ||
if (enabled.value() == false) { | ||
return; | ||
} | ||
for (String field : context.getFieldExistsFields()) { | ||
context.doc().add(new Field(NAME, field, Defaults.FIELD_TYPE)); | ||
} | ||
} | ||
|
||
@Override | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -292,6 +292,16 @@ public void addIgnoredField(String field) { | |
public Collection<String> getIgnoredFields() { | ||
return in.getIgnoredFields(); | ||
} | ||
|
||
@Override | ||
public void addFieldExistsField(String field) { | ||
in.addFieldExistsField(field); | ||
} | ||
|
||
@Override | ||
public Collection<String> getFieldExistsFields() { | ||
return in.getFieldExistsFields(); | ||
} | ||
} | ||
|
||
public static class InternalParseContext extends ParseContext { | ||
|
@@ -307,6 +317,7 @@ public static class InternalParseContext extends ParseContext { | |
private final Map<String, ObjectMapper> dynamicObjectMappers = new HashMap<>(); | ||
private final List<RuntimeField> dynamicRuntimeFields = new ArrayList<>(); | ||
private final Set<String> ignoredFields = new HashSet<>(); | ||
private final Set<String> fieldNameFields = new HashSet<>(); | ||
private Field version; | ||
private SeqNoFieldMapper.SequenceIDFields seqID; | ||
private long numNestedDocs; | ||
|
@@ -490,6 +501,16 @@ public void addIgnoredField(String field) { | |
public Collection<String> getIgnoredFields() { | ||
return Collections.unmodifiableCollection(ignoredFields); | ||
} | ||
|
||
@Override | ||
public void addFieldExistsField(String field) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I slightly prefer the previous name, shall we call it addFieldToFieldNames ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I ended up with |
||
fieldNameFields.add(field); | ||
} | ||
|
||
@Override | ||
public Collection<String> getFieldExistsFields() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getFieldNames? |
||
return Collections.unmodifiableCollection(fieldNameFields); | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -509,6 +530,19 @@ public Collection<String> getIgnoredFields() { | |
*/ | ||
public abstract Collection<String> getIgnoredFields(); | ||
|
||
/** | ||
* Add the given {@code field} to the _fieldnames field | ||
* | ||
* Use this if an exists query run against the field cannot use docvalues | ||
* or norms. | ||
*/ | ||
public abstract void addFieldExistsField(String field); | ||
|
||
/** | ||
* Return the collection of fields to be added to the _fieldnames field | ||
*/ | ||
public abstract Collection<String> getFieldExistsFields(); | ||
|
||
public abstract Mapper.TypeParser.ParserContext parserContext(DateFormatter dateFormatter); | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a way to keep this assertion? I vaguely remember adding it while cleaning up some inconsistencies around using field_names where it would not make sense
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added an assertion in FieldNamesFieldMapper.postParse()