Adapting to merging GetField and SearchHitField to DocumentField (elastic/x-pack-elasticsearch#1860)
Follow up to changes in https://github.com/elastic/elasticsearch/pull/25361 Original commit: elastic/x-pack-elasticsearch@5b1ca009f6
This commit is contained in:
parent
5dc9fed9da
commit
3ff5ee3f47
|
@ -5,8 +5,8 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.ml.datafeed.extractor.scroll;
|
||||
|
||||
import org.elasticsearch.common.document.DocumentField;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.SearchHitField;
|
||||
import org.joda.time.base.BaseDateTime;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -82,7 +82,7 @@ abstract class ExtractedField {
|
|||
|
||||
@Override
|
||||
public Object[] value(SearchHit hit) {
|
||||
SearchHitField keyValue = hit.field(name);
|
||||
DocumentField keyValue = hit.field(name);
|
||||
if (keyValue != null) {
|
||||
List<Object> values = keyValue.getValues();
|
||||
return values.toArray(new Object[values.size()]);
|
||||
|
|
|
@ -10,13 +10,13 @@ import org.elasticsearch.action.search.SearchRequestBuilder;
|
|||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.search.ShardSearchFailure;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.document.DocumentField;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.ScriptType;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.SearchHitField;
|
||||
import org.elasticsearch.search.SearchHits;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
@ -453,10 +453,10 @@ public class ScrollDataExtractorTests extends ESTestCase {
|
|||
List<SearchHit> hits = new ArrayList<>();
|
||||
for (int i = 0; i < timestamps.size(); i++) {
|
||||
SearchHit hit = new SearchHit(randomInt());
|
||||
Map<String, SearchHitField> fields = new HashMap<>();
|
||||
fields.put(extractedFields.timeField(), new SearchHitField("time", Arrays.asList(timestamps.get(i))));
|
||||
fields.put("field_1", new SearchHitField("field_1", Arrays.asList(field1Values.get(i))));
|
||||
fields.put("field_2", new SearchHitField("field_2", Arrays.asList(field2Values.get(i))));
|
||||
Map<String, DocumentField> fields = new HashMap<>();
|
||||
fields.put(extractedFields.timeField(), new DocumentField("time", Arrays.asList(timestamps.get(i))));
|
||||
fields.put("field_1", new DocumentField("field_1", Arrays.asList(field1Values.get(i))));
|
||||
fields.put("field_2", new DocumentField("field_2", Arrays.asList(field2Values.get(i))));
|
||||
hit.fields(fields);
|
||||
hits.add(hit);
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.elasticsearch.cluster.metadata.MappingMetaData;
|
|||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
||||
import org.elasticsearch.common.document.DocumentField;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.text.Text;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
|
@ -34,7 +35,6 @@ import org.elasticsearch.index.Index;
|
|||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.SearchHitField;
|
||||
import org.elasticsearch.search.SearchHits;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.xpack.ml.MlMetadata;
|
||||
|
@ -880,9 +880,9 @@ public class JobProviderTests extends ESTestCase {
|
|||
for (Map<String, Object> map : source) {
|
||||
Map<String, Object> _source = new HashMap<>(map);
|
||||
|
||||
Map<String, SearchHitField> fields = new HashMap<>();
|
||||
fields.put("field_1", new SearchHitField("field_1", Collections.singletonList("foo")));
|
||||
fields.put("field_2", new SearchHitField("field_2", Collections.singletonList("foo")));
|
||||
Map<String, DocumentField> fields = new HashMap<>();
|
||||
fields.put("field_1", new DocumentField("field_1", Collections.singletonList("foo")));
|
||||
fields.put("field_2", new DocumentField("field_2", Collections.singletonList("foo")));
|
||||
|
||||
SearchHit hit = new SearchHit(123, String.valueOf(map.hashCode()), new Text("foo"), fields)
|
||||
.sourceRef(XContentFactory.jsonBuilder().map(_source).bytes());
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
package org.elasticsearch.xpack.ml.test;
|
||||
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.document.DocumentField;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.SearchHitField;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
@ -20,7 +20,7 @@ import java.util.Map;
|
|||
public class SearchHitBuilder {
|
||||
|
||||
private final SearchHit hit;
|
||||
private final Map<String, SearchHitField> fields;
|
||||
private final Map<String, DocumentField> fields;
|
||||
|
||||
public SearchHitBuilder(int docId) {
|
||||
hit = new SearchHit(docId);
|
||||
|
@ -32,7 +32,7 @@ public class SearchHitBuilder {
|
|||
}
|
||||
|
||||
public SearchHitBuilder addField(String name, List<Object> values) {
|
||||
fields.put(name, new SearchHitField(name, values));
|
||||
fields.put(name, new DocumentField(name, values));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue