This repository has been archived by the owner on Jun 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b17791c
commit ed18c0c
Showing
6 changed files
with
267 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/bash -e | ||
|
||
curl -X GET "http://localhost:9200/ecommerce/_search" -H 'Content-Type: application/json' -d' | ||
{ | ||
"query": { | ||
"match": { | ||
"text_entry": "I am the night" | ||
} | ||
}, | ||
"ext": { | ||
"ubi_parameters": { | ||
"query_id": "1234512345" | ||
} | ||
} | ||
} | ||
}' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* 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 com.o19s.ubi.ext; | ||
|
||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
import org.opensearch.core.xcontent.XContentParser; | ||
import org.opensearch.search.SearchExtBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
public class UbiParamExtBuilder extends SearchExtBuilder { | ||
|
||
// The name of the "ext" section containing UBI parameters. | ||
public static final String PARAMETER_NAME = "ubi_parameters"; | ||
|
||
private UbiParameters params; | ||
|
||
public UbiParamExtBuilder() { | ||
|
||
} | ||
|
||
public UbiParamExtBuilder(StreamInput input) throws IOException { | ||
this.params = new UbiParameters(input); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(this.getClass(), this.params); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
|
||
if (!(obj instanceof UbiParamExtBuilder)) { | ||
return false; | ||
} | ||
|
||
return this.params.equals(((UbiParamExtBuilder) obj).getParams()); | ||
} | ||
|
||
@Override | ||
public String getWriteableName() { | ||
return PARAMETER_NAME; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
this.params.writeTo(out); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
return builder.value(this.params); | ||
} | ||
|
||
public static UbiParamExtBuilder parse(XContentParser parser) throws IOException { | ||
final UbiParamExtBuilder builder = new UbiParamExtBuilder(); | ||
UbiParameters params = UbiParameters.parse(parser); | ||
builder.setParams(params); | ||
return builder; | ||
} | ||
|
||
public UbiParameters getParams() { | ||
return params; | ||
} | ||
|
||
public void setParams(UbiParameters params) { | ||
this.params = params; | ||
} | ||
|
||
} |
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,39 @@ | ||
/* | ||
* 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 com.o19s.ubi.ext; | ||
|
||
import org.opensearch.action.search.SearchRequest; | ||
import org.opensearch.search.SearchExtBuilder; | ||
|
||
import java.util.Optional; | ||
|
||
public class UbiParamUtil { | ||
|
||
public static UbiParameters getUbiParameters(SearchRequest request) { | ||
UbiParamExtBuilder builder = null; | ||
if (request.source() != null && request.source().ext() != null && !request.source().ext().isEmpty()) { | ||
Optional<SearchExtBuilder> b = request | ||
.source() | ||
.ext() | ||
.stream() | ||
.filter(bldr -> UbiParamExtBuilder.PARAMETER_NAME.equals(bldr.getWriteableName())) | ||
.findFirst(); | ||
if (b.isPresent()) { | ||
builder = (UbiParamExtBuilder) b.get(); | ||
} | ||
} | ||
|
||
UbiParameters params = null; | ||
if (builder != null) { | ||
params = builder.getParams(); | ||
} | ||
|
||
return params; | ||
} | ||
} |
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,83 @@ | ||
/* | ||
* 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 com.o19s.ubi.ext; | ||
|
||
import org.opensearch.core.ParseField; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
import org.opensearch.core.common.io.stream.Writeable; | ||
import org.opensearch.core.xcontent.ObjectParser; | ||
import org.opensearch.core.xcontent.ToXContentObject; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
import org.opensearch.core.xcontent.XContentParser; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
public class UbiParameters implements Writeable, ToXContentObject { | ||
|
||
private static final ObjectParser<UbiParameters, Void> PARSER; | ||
private static final ParseField QUERY_ID = new ParseField("query_id"); | ||
|
||
static { | ||
PARSER = new ObjectParser<>(UbiParamExtBuilder.PARAMETER_NAME, UbiParameters::new); | ||
PARSER.declareString(UbiParameters::setQueryId, QUERY_ID); | ||
} | ||
|
||
private String queryId; | ||
|
||
public UbiParameters(String queryId) { | ||
this.queryId = queryId; | ||
} | ||
|
||
public UbiParameters(StreamInput input) throws IOException { | ||
this.queryId = input.readString(); | ||
} | ||
|
||
public UbiParameters() { | ||
|
||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder xContentBuilder, Params params) throws IOException { | ||
return xContentBuilder | ||
.field(QUERY_ID.getPreferredName(), this.queryId); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeOptionalString(queryId); | ||
} | ||
|
||
public static UbiParameters parse(XContentParser parser) throws IOException { | ||
return PARSER.parse(parser, null); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
|
||
UbiParameters other = (UbiParameters) o; | ||
return Objects.equals(this.queryId, other.getQueryId()); | ||
} | ||
|
||
public String getQueryId() { | ||
return queryId; | ||
} | ||
|
||
public void setQueryId(String conversationId) { | ||
this.queryId = conversationId; | ||
} | ||
|
||
} |