Skip to content

Commit

Permalink
fix(repository-elasticsearch): use a mapping for labels compatible wi…
Browse files Browse the repository at this point in the history
…th opensearch
  • Loading branch information
tchiotludo committed Jun 22, 2022
1 parent 8a17519 commit d87a83c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,10 @@ public ArrayListTotal<Flow> 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));
}
});
}
Expand Down Expand Up @@ -318,6 +318,14 @@ public Flow save(Flow flow, CrudEventType crudEventType) throws ConstraintViolat
try {
Map<String, Object> 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);
Expand Down
9 changes: 7 additions & 2 deletions repository-elasticsearch/src/main/resources/mappings/flow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d87a83c

Please sign in to comment.