ElasticSearch, multi-match with filter?

后端 未结 4 345
情深已故
情深已故 2021-01-30 08:30

I have a multi-match query in ES, and wish to add a filter.

{
  \"multi_match\" : {
    \"query\" : \"this is a test\",
    \"fields\" : [ \"subject^2\", \"messa         


        
4条回答
  •  时光取名叫无心
    2021-01-30 09:15

    Try this:

    [
            "index" => 'shop_1', //index_name,
            "type" => 'shop', //type_name,
            "from" => 0, //offset
            "size" => 30, //limit
            "body" => [
                "query" => [
                    "bool" => [
                        "must" =>   [
                                        "match" => [
                                            "category" => 'men' // results must contain 'men' in category field
                                        ]
                                    ]
                    ]
                ],
                "_source" => [ // fields to retrieve
                                "id",
                                "product_id",
                                "item_title",
                                "item_slug",
                                "item_sku"
                            ],
                "sort" => [
                    [
                        "_score" => [
                            "order" => "desc" // order by score desc
                        ]
                    ]
                ]
    
          ],
    ];
    

提交回复
热议问题