# Update\_By\_Query in elasticsearch\_dsl matches \<field\> but doesn't match \<object\>.\<field\>

**URL:** <https://discuss.elastic.co/t/update-by-query-in-elasticsearch-dsl-matches-field-but-doesnt-match-object-field/325889>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [February 18, 2023, 3:34pm UTC](https://discuss.elastic.co/t/update-by-query-in-elasticsearch-dsl-matches-field-but-doesnt-match-object-field/325889 "2023-02-18T15:34:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![brunofl](https://avatars.discourse-cdn.com/v4/letter/b/9de053/32.png) [@brunofl](https://discuss.elastic.co/u/brunofl)\
**Post date:** [February 18, 2023, 3:34pm UTC](https://discuss.elastic.co/t/update-by-query-in-elasticsearch-dsl-matches-field-but-doesnt-match-object-field/325889/1 "2023-02-18T15:34:56Z")

</div>

I managed to do an update\_by\_query script with elasticsearch\_dsl.

```auto
response = ubq.script(source="pm_data_source.hw_alias' = params.new_ap_name",lang="painless",params={"new_ap_name": new_ap})\
        .query("match", pm_data_source.hw_alias = old_ap ).execute()

```

Current problem is: in the `query()` I am unable to match fields inside an object. Do you happen to know how to do this?

---

<div class="post-metadata">

**Author:** ![brunofl](https://avatars.discourse-cdn.com/v4/letter/b/9de053/32.png) [@brunofl](https://discuss.elastic.co/u/brunofl)\
**Post date:** [February 28, 2023, 10:33pm UTC](https://discuss.elastic.co/t/update-by-query-in-elasticsearch-dsl-matches-field-but-doesnt-match-object-field/325889/2 "2023-02-28T22:33:56Z")

</div>

Solved with the following:

```auto
update = ubq.script(source="ctx._source.object_name.field_name = params.new_ap_name; ctx._source.radio.Accesspoint_name = params.new_ap_name; ",
         lang="painless",
         params={ "new_ap_name": "new_field_value" }).update_from_dict({
                    "query": {
                           "bool": {
                                  "must": [
                                         { "match": { "object_name.field_name": "new_field_value" } },
                                         { "match": { "account_name": "Filters documents of specific customer" } }
                                   ]
                            }
                         }
}).params(request_timeout=3600).params(wait_for_completion=False).params(wait_for_active_shards=1).params(refresh=True)
response = update.execute()

```

The old and new field values can be provided by your python script.  
hope this helps

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 28, 2023, 10:34pm UTC](https://discuss.elastic.co/t/update-by-query-in-elasticsearch-dsl-matches-field-but-doesnt-match-object-field/325889/3 "2023-03-28T22:34:34Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
