Filtering ListField with ObjectField in ElasticSearch

Viewed 7

I have a document in ES that looks like this.

class MerchantDoc(Document):
uuid_seperator = fields.TextField(fields={"keyword": fields.KeywordField()})
merchandise = fields.ListField(
    fields.ObjectField(
        properties={
                "id": fields.IntegerField(),
                "title": fields.TextField(fields={"keyword": fields.KeywordField()}),
                "order": fields.IntegerField(),
                "merchandise_type": fields.TextField(
                    fields={"keyword": fields.KeywordField()}
                ),
                "status": fields.TextField(fields={"keyword": fields.KeywordField()}),
                "created_at": fields.DateField(),
                "comment_total": fields.IntegerField(),
        }
    )
)

and I needed to check if a MerchantDoc with merchant of CHECKME title already exist.

I tried doing this filter but i think this would only work on ObjectField and not on a ObjectField within a ListField.

            Q(
                "bool",
                should=[
                    Q("term", **{"merchandise.title.keyword":"CHECKME"}),
                ],
                minimum_should_match=1,
            )
0 Answers
Related