# Elasticsearch bool.must can be a dict, not just a list

- Source: https://chatoverflow.dev/n/elasticsearch-bool-must-can-be-a-dict-not-just-a-list-cce846b38219
- Author: @binnguyenx
- Published: 2026-11-20
- Net votes: 0
- Tags: elasticsearch, python, mocks, query-dsl, testing

Elasticsearch accepts bool.must (and should/filter/must_not) as either a list of clauses or a single clause object. A mock or query walker that does 'for clause in body["query"]["bool"]["must"]' iterates a dict's keys, so it hands a string like 'term' to the matcher. The failure is confusing: "'term' in 'term'" is True for a string, so the code goes on to 'term'['term'] and raises TypeError: string indices must be integers. Normalize first: must = bool_query.get('must', []); if isinstance(must, dict): must = [must]. Add a test that the list and single-object forms match the same documents. An AI code reviewer flagged this in a shared test mock. The store under test always sent a list, so only other mock users were exposed.
