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 CreateAnomalyDetectorTool doesn't support data streams and alias #423

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,9 @@ public <T> void run(Map<String, String> parameters, ActionListener<T> listener)
throw new IllegalArgumentException("No mapping found for the index: " + indexName);
}

MappingMetadata mappingMetadata;
// when the index name is wildcard pattern, we fetch the mappings of the first index
if (indexName.contains("*")) {
mappingMetadata = mappings.get((String) mappings.keySet().toArray()[0]);
} else {
mappingMetadata = mappings.get(indexName);
}
// when the index name is wildcard pattern, data stream, or alias, we fetch the mappings of the first index
String firstIndexName = (String) mappings.keySet().toArray()[0];
gaobinlong marked this conversation as resolved.
Show resolved Hide resolved
MappingMetadata mappingMetadata = mappings.get(firstIndexName);

Map<String, Object> mappingSource = (Map<String, Object>) mappingMetadata.getSourceAsMap().get("properties");
if (Objects.isNull(mappingSource)) {
Expand Down Expand Up @@ -224,7 +220,7 @@ public <T> void run(Map<String, String> parameters, ActionListener<T> listener)
.collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue));

// construct the prompt
String prompt = constructPrompt(filteredMapping, indexName);
String prompt = constructPrompt(filteredMapping, firstIndexName);
RemoteInferenceInputDataSet inputDataSet = RemoteInferenceInputDataSet
.builder()
.parameters(Collections.singletonMap("prompt", prompt))
Expand Down Expand Up @@ -278,7 +274,7 @@ public <T> void run(Map<String, String> parameters, ActionListener<T> listener)
Map<String, String> result = ImmutableMap
.of(
OUTPUT_KEY_INDEX,
indexName,
firstIndexName,
OUTPUT_KEY_CATEGORY_FIELD,
categoryField,
OUTPUT_KEY_AGGREGATION_FIELD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class CreateAnomalyDetectorToolTests {
"{\"index\":\"http_logs\",\"categoryField\":\"\",\"aggregationField\":\"response,responseLatency\",\"aggregationMethod\":\"count,avg\",\"dateFields\":\"date\"}";

private String mockedResultForIndexPattern =
"{\"index\":\"http_logs*\",\"categoryField\":\"\",\"aggregationField\":\"response,responseLatency\",\"aggregationMethod\":\"count,avg\",\"dateFields\":\"date\"}";
"{\"index\":\"http_logs\",\"categoryField\":\"\",\"aggregationField\":\"response,responseLatency\",\"aggregationMethod\":\"count,avg\",\"dateFields\":\"date\"}";

@Before
public void setup() {
Expand Down
Loading