diff --git a/repository-elasticsearch/src/main/java/io/kestra/repository/elasticsearch/ElasticSearchFlowRepository.java b/repository-elasticsearch/src/main/java/io/kestra/repository/elasticsearch/ElasticSearchFlowRepository.java index 544b12d135..82752b5e83 100644 --- a/repository-elasticsearch/src/main/java/io/kestra/repository/elasticsearch/ElasticSearchFlowRepository.java +++ b/repository-elasticsearch/src/main/java/io/kestra/repository/elasticsearch/ElasticSearchFlowRepository.java @@ -205,10 +205,10 @@ public ArrayListTotal find( if (labels != null) { labels.forEach((key, value) -> { + bool.must(QueryBuilders.termQuery("labelsMap.key", key)); + if (value != null) { - bool.must(QueryBuilders.termQuery("labels." + key, value)); - } else { - bool.must(QueryBuilders.existsQuery("labels." + key)); + bool.must(QueryBuilders.termQuery("labelsMap.value", value)); } }); } @@ -318,6 +318,14 @@ public Flow save(Flow flow, CrudEventType crudEventType) throws ConstraintViolat try { Map flowMap = JacksonMapper.toMap(flow); flowMap.put("sourceCode", YAML_MAPPER.writeValueAsString(flow)); + if (flow.getLabels() != null) { + flowMap.put("labelsMap", flow.getLabels() + .entrySet() + .stream() + .map(e -> Map.of("key", e.getKey(), "value", e.getValue())) + .collect(Collectors.toList()) + ); + } json = JSON_MAPPER.writeValueAsString(flowMap); } catch (JsonProcessingException e) { throw new RuntimeException(e); diff --git a/repository-elasticsearch/src/main/resources/mappings/flow.yml b/repository-elasticsearch/src/main/resources/mappings/flow.yml index a1c18683d5..da453b6890 100644 --- a/repository-elasticsearch/src/main/resources/mappings/flow.yml +++ b/repository-elasticsearch/src/main/resources/mappings/flow.yml @@ -37,10 +37,15 @@ properties: type: keyword type: type: keyword - labels: - type: flattened deleted: type: boolean sourceCode: type: text term_vector: with_positions_offsets + labelsMap: + type: object + properties: + key: + type: keyword + value: + type: keyword \ No newline at end of file