-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Aggregatable mutli-fields are at the moment wrongly mapped as normal doc_value fields and thus they support fetching from source. However, they do not exist in the source. This results to failure to extract such fields. This commit fixes this bug. While a fix could be worked out on top of the existing code, it is evident the extraction logic has become difficult to understand and maintain. As we also want to deduplicate multi-fields for data frame analytics, it seemed appropriate to refactor the code to simplify and better handle the extraction of multi-fields. Relates #48756 Backport of #48770
- Loading branch information
1 parent
e1e9b23
commit 1f662e0
Showing
30 changed files
with
1,214 additions
and
675 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/extractor/AbstractField.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.ml.extractor; | ||
|
||
import org.elasticsearch.common.document.DocumentField; | ||
import org.elasticsearch.search.SearchHit; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
abstract class AbstractField implements ExtractedField { | ||
|
||
private final String name; | ||
|
||
private final Set<String> types; | ||
|
||
AbstractField(String name, Set<String> types) { | ||
this.name = Objects.requireNonNull(name); | ||
this.types = Objects.requireNonNull(types); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public String getSearchField() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public Set<String> getTypes() { | ||
return types; | ||
} | ||
|
||
protected Object[] getFieldValue(SearchHit hit) { | ||
DocumentField keyValue = hit.field(getSearchField()); | ||
if (keyValue != null) { | ||
List<Object> values = keyValue.getValues(); | ||
return values.toArray(new Object[0]); | ||
} | ||
return new Object[0]; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/extractor/DocValueField.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.ml.extractor; | ||
|
||
import org.elasticsearch.common.Nullable; | ||
import org.elasticsearch.search.SearchHit; | ||
|
||
import java.util.Set; | ||
|
||
public class DocValueField extends AbstractField { | ||
|
||
public DocValueField(String name, Set<String> types) { | ||
super(name, types); | ||
} | ||
|
||
@Override | ||
public Method getMethod() { | ||
return Method.DOC_VALUE; | ||
} | ||
|
||
@Override | ||
public Object[] value(SearchHit hit) { | ||
return getFieldValue(hit); | ||
} | ||
|
||
@Override | ||
public boolean supportsFromSource() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public ExtractedField newFromSource() { | ||
return new SourceField(getSearchField(), getTypes()); | ||
} | ||
|
||
@Override | ||
public boolean isMultiField() { | ||
return false; | ||
} | ||
|
||
@Nullable | ||
public String getDocValueFormat() { | ||
return null; | ||
} | ||
} |
Oops, something went wrong.