How to filter in elasticsearch?

                q = Q(
                    'bool',
                        # must_not=[Q('match', is_active="true"), Q('match', sales_block="False")],
                        must=[
                            Q(
                            'multi_match',
                            query = query,
                            fields = ['item_id.group_id._*name','item_id.group_id._name*','item_id.group_id.name_2gram','item_id.group_id.name_3gram','item_id.group_id.name','item_id.group_id.category_id.name','item_id.group_id.category_id.name_2gram','item_id.group_id.category_id.name_3gram','item_id.group_id.category_id._*name','item_id.group_id.category_id.name_*','item_id.name','item_id.name_2gram','item_id.name_3gram','item_id._*name','item_id.name_*''name','*_name','name_*','name._2gram','name._3gram','barcode_number','barcode_number._2gram','barcode_number._3gram','barcode_number_*','*_barcode_number'],
                            type="best_fields", #best_fields
                            max_expansions = 3,
                            boost=1,
                            fuzziness="0.6",
                            prefix_length=0,
                            slop=3,
                            operator="and"
                            # filter=[{'is_active':True,'sales_block':False}])
                            )
                        ]

                    )| Q(
                        'wildcard',
                        name={"value":f"*{query}"},
                    ) | Q(
                        'wildcard',
                        name={"value":f"{query}*"},
                    )
                search1 = search.query(q)
                search1 = search1.execute()
                v=NewsDocumentSerializer(search1,many=True)
                page = self.paginate_queryset(v.data)
                return Response ({'status':'success','response_code':200,"data":self.get_paginated_response(page)})

this is my query , but I need filteration ie, i need products that have is_active=True and is_active=False

got it !!


                        filter = [
                            {
                                "term":{
                                    "is_active":True
                                }
                            },
                            {
                                "term":{
                                    "is_delete":False
                                }
                            }
                        ]

may be useful for others....!!

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