Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix name bug #139

Merged
merged 3 commits into from
Jan 23, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/main/java/org/opensearch/agent/tools/PPLTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,12 @@ public <T> void run(Map<String, String> parameters, ActionListener<T> listener)
GetMappingsRequest getMappingsRequest = buildGetMappingRequest(indexName);
client.admin().indices().getMappings(getMappingsRequest, ActionListener.<GetMappingsResponse>wrap(getMappingsResponse -> {
Map<String, MappingMetadata> mappings = getMappingsResponse.getMappings();
if (mappings.size() == 0) {
throw new IllegalArgumentException("No matching index with index name: " + indexName);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems we should useNo matching mapping with ..., is this index from user's input?

}
client.search(searchRequest, ActionListener.<SearchResponse>wrap(searchResponse -> {
SearchHit[] searchHits = searchResponse.getHits().getHits();
String tableInfo = constructTableInfo(searchHits, mappings, indexName);
String tableInfo = constructTableInfo(searchHits, mappings);
String prompt = constructPrompt(tableInfo, question, indexName);
RemoteInferenceInputDataSet inputDataSet = RemoteInferenceInputDataSet
.builder()
Expand Down Expand Up @@ -288,9 +291,9 @@ private GetMappingsRequest buildGetMappingRequest(String indexName) {
return getMappingsRequest;
}

private String constructTableInfo(SearchHit[] searchHits, Map<String, MappingMetadata> mappings, String indexName)
throws PrivilegedActionException {
MappingMetadata mappingMetadata = mappings.get(indexName);
private String constructTableInfo(SearchHit[] searchHits, Map<String, MappingMetadata> mappings) throws PrivilegedActionException {
String firstIndexName = (String) mappings.keySet().toArray()[0];
MappingMetadata mappingMetadata = mappings.get(firstIndexName);
Map<String, Object> mappingSource = (Map<String, Object>) mappingMetadata.getSourceAsMap().get("properties");
Map<String, String> fieldsToType = new HashMap<>();
extractNamesTypes(mappingSource, fieldsToType, "");
Expand Down
Loading