-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'opensearch-project:main' into cs-tasks-response
- Loading branch information
Showing
111 changed files
with
1,590 additions
and
590 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 was deleted.
Oops, something went wrong.
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 @@ | ||
8e87d93868271da754a7c22517b3dbbcf84fc7f9 |
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
1 change: 0 additions & 1 deletion
1
modules/lang-expression/licenses/lucene-expressions-9.6.0.jar.sha1
This file was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
modules/lang-expression/licenses/lucene-expressions-9.7.0-snapshot-4d1ed9e.jar.sha1
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 @@ | ||
441c6341e75f06b834c992084f21556681963ea6 |
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
151 changes: 151 additions & 0 deletions
151
...mon/src/main/java/org/opensearch/search/pipeline/common/RenameFieldResponseProcessor.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,151 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.search.pipeline.common; | ||
|
||
import org.opensearch.action.search.SearchRequest; | ||
import org.opensearch.action.search.SearchResponse; | ||
import org.opensearch.common.bytes.BytesReference; | ||
import org.opensearch.common.collect.Tuple; | ||
import org.opensearch.common.document.DocumentField; | ||
import org.opensearch.common.xcontent.XContentHelper; | ||
import org.opensearch.core.xcontent.MediaType; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
import org.opensearch.ingest.ConfigurationUtils; | ||
import org.opensearch.search.SearchHit; | ||
import org.opensearch.search.pipeline.Processor; | ||
import org.opensearch.search.pipeline.SearchRequestProcessor; | ||
import org.opensearch.search.pipeline.SearchResponseProcessor; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* This is a {@link SearchRequestProcessor} that renames a field before returning the search response | ||
*/ | ||
public class RenameFieldResponseProcessor extends AbstractProcessor implements SearchResponseProcessor { | ||
|
||
private final String oldField; | ||
private final String newField; | ||
private final boolean ignoreMissing; | ||
|
||
/** | ||
* Key to reference this processor type from a search pipeline. | ||
*/ | ||
public static final String TYPE = "rename_field"; | ||
|
||
/** | ||
* Constructor that takes a target field to rename and the new name | ||
* | ||
* @param tag processor tag | ||
* @param description processor description | ||
* @param oldField name of field to be renamed | ||
* @param newField name of field that will replace the old field | ||
* @param ignoreMissing if true, do not throw error if oldField does not exist within search response | ||
*/ | ||
public RenameFieldResponseProcessor(String tag, String description, String oldField, String newField, boolean ignoreMissing) { | ||
super(tag, description); | ||
this.oldField = oldField; | ||
this.newField = newField; | ||
this.ignoreMissing = ignoreMissing; | ||
} | ||
|
||
@Override | ||
public String getType() { | ||
return TYPE; | ||
} | ||
|
||
/** | ||
* Getter function for oldField | ||
* @return oldField | ||
*/ | ||
public String getOldField() { | ||
return oldField; | ||
} | ||
|
||
/** | ||
* Getter function for newField | ||
* @return newField | ||
*/ | ||
public String getNewField() { | ||
return newField; | ||
} | ||
|
||
/** | ||
* Getter function for ignoreMissing | ||
* @return ignoreMissing | ||
*/ | ||
public boolean isIgnoreMissing() { | ||
return ignoreMissing; | ||
} | ||
|
||
@Override | ||
public SearchResponse processResponse(SearchRequest request, SearchResponse response) throws Exception { | ||
boolean foundField = false; | ||
|
||
SearchHit[] hits = response.getHits().getHits(); | ||
for (SearchHit hit : hits) { | ||
Map<String, DocumentField> fields = hit.getFields(); | ||
if (fields.containsKey(oldField)) { | ||
foundField = true; | ||
DocumentField old = hit.removeDocumentField(oldField); | ||
DocumentField newDocField = new DocumentField(newField, old.getValues()); | ||
hit.setDocumentField(newField, newDocField); | ||
} | ||
|
||
if (hit.hasSource()) { | ||
BytesReference sourceRef = hit.getSourceRef(); | ||
Tuple<? extends MediaType, Map<String, Object>> typeAndSourceMap = XContentHelper.convertToMap( | ||
sourceRef, | ||
false, | ||
(MediaType) null | ||
); | ||
|
||
Map<String, Object> sourceAsMap = typeAndSourceMap.v2(); | ||
if (sourceAsMap.containsKey(oldField)) { | ||
foundField = true; | ||
Object val = sourceAsMap.remove(oldField); | ||
sourceAsMap.put(newField, val); | ||
|
||
XContentBuilder builder = XContentBuilder.builder(typeAndSourceMap.v1().xContent()); | ||
builder.map(sourceAsMap); | ||
hit.sourceRef(BytesReference.bytes(builder)); | ||
} | ||
} | ||
|
||
if (!foundField && !ignoreMissing) { | ||
throw new IllegalArgumentException("Document with id " + hit.getId() + " is missing field " + oldField); | ||
} | ||
} | ||
|
||
return response; | ||
} | ||
|
||
/** | ||
* This is a factor that creates the RenameResponseProcessor | ||
*/ | ||
public static final class Factory implements Processor.Factory<SearchResponseProcessor> { | ||
|
||
/** | ||
* Constructor for factory | ||
*/ | ||
Factory() {} | ||
|
||
@Override | ||
public RenameFieldResponseProcessor create( | ||
Map<String, Processor.Factory<SearchResponseProcessor>> processorFactories, | ||
String tag, | ||
String description, | ||
Map<String, Object> config | ||
) throws Exception { | ||
String oldField = ConfigurationUtils.readStringProperty(TYPE, tag, config, "field"); | ||
String newField = ConfigurationUtils.readStringProperty(TYPE, tag, config, "target_field"); | ||
boolean ignoreMissing = ConfigurationUtils.readBooleanProperty(TYPE, tag, config, "ignore_missing", false); | ||
return new RenameFieldResponseProcessor(tag, description, oldField, newField, ignoreMissing); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.