Skip to content

Commit

Permalink
Include source for update_by_query as a hacking example
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosdelest committed Nov 1, 2023
1 parent 010d302 commit 64b16dc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ protected UpdateByQueryRequest buildRequest(RestRequest request, NamedWriteableR
consumers.put("script", o -> internal.setScript(Script.parse(o)));
consumers.put("max_docs", s -> setMaxDocsValidateIdentical(internal, ((Number) s).intValue()));

// TODO There surely must be a better way of doing this
request.params().put("_source_includes", "*");
parseInternalRequest(internal, request, namedWriteableRegistry, consumers);

internal.setPipeline(request.param("pipeline"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

package org.elasticsearch.ingest;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.DocWriteRequest;
import org.elasticsearch.action.index.IndexRequest;
Expand All @@ -33,6 +35,7 @@

public class FieldInferenceBulkRequestPreprocessor extends AbstractBulkRequestPreprocessor {

private static final Logger logger = LogManager.getLogger(FieldInferenceBulkRequestPreprocessor.class);
public static final String SEMANTIC_TEXT_ORIGIN = "semantic_text";

private final IndicesService indicesService;
Expand Down Expand Up @@ -99,11 +102,6 @@ public boolean shouldExecuteOnIngestNode() {
}

private boolean fieldNeedsInference(IndexRequest indexRequest, String fieldName, Object fieldValue) {

if (fieldValue instanceof String == false) {
return false;
}

return getModelForField(indexRequest, fieldName) != null;
}

Expand Down Expand Up @@ -147,13 +145,17 @@ private void runInferenceForFields(
String fieldName = fieldNames.get(0);
List<String> nextFieldNames = fieldNames.subList(1, fieldNames.size());
final String fieldValue = ingestDocument.getFieldValue(fieldName, String.class);
if (fieldValue == null) {
Object existingInference = ingestDocument.getFieldValue(SemanticTextInferenceFieldMapper.FIELD_NAME + "." + fieldName, Object.class, true);
if (fieldValue == null || existingInference != null) {
// Run inference for next field
logger.info("Skipping inference for field [" + fieldName + "]");
runInferenceForFields(indexRequest, nextFieldNames, ref, position, ingestDocument, onFailure);
return;
}

String modelForField = getModelForField(indexRequest, fieldName);
assert modelForField != null : "Field " + fieldName + " has no model associated in mappings";
logger.info("Calculating inference for field [" + fieldName + "]");

// TODO Hardcoding task type, how to get that from model ID?
InferenceAction.Request inferenceRequest = new InferenceAction.Request(
Expand Down

0 comments on commit 64b16dc

Please sign in to comment.