Last active
February 1, 2021 17:17
-
-
Save salami-art/7224b00fcf9532a7eceec5c535406291 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def combine_query(query, piece) | |
# this function always receives its previous return value | |
_query = {}.merge(query) # also tried Hash.new(), query.dup, query.clone | |
_query['query'] ||= {} | |
_query['query']['bool'] ||= {} | |
_query['query']['bool']['must'] ||= [] | |
_query['query']['bool']['must'] << piece | |
_query | |
end | |
def aggregate(by: {}, query: {}, &block) | |
results = search_index(body: query.dup.merge({aggs: get_aggregations(by)})) | |
results.each do |result| | |
display, value = result['key'].split('|') | |
yield value, display | |
end | |
end | |
def main_job_perform_function | |
# [ .... within a loop ....] | |
q = get_desided_query.freeze | |
# q is the object that is being unexpectedly mutated | |
aggregate by: {field: 'my_field'}, query: q do |k, v| | |
new_query = combine_query(q, get_other_condition('my_field', k)) | |
update_index(query: new_query['query'], script: populate_array_field({ myfield: myvalue })) | |
new_query = 'ASDASAd' | |
log_debug(new_query) | |
end | |
# [ .... ] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment