具有多个属性和值的Elasticsearch查询

时间:2017-01-24 15:59:26

标签: php elasticsearch drupal

我尝试在php中构造一个具有不同attribut的查询: 以下代码工作:

$searchParams = [
    'body' => [
        "from"=> 0,
        "size"=> 30000,
        'query' => [
            'filtered'=> [
                'filter' => [
                    'bool' => [
                        'must' => [
                            'terms' => [
                                'field_support' => [105,106,1896,1897]
                            ]
                        ]

                     ]
                ]
            ]
        ]
    ]
];

但是当我添加" term"它无法正常工作:

$searchParams = [
    'body' => [
        "from"=> 0,
        "size"=> 30000,
        'query' => [
            'filtered'=> [
                'filter' => [
                    'bool' => [
                        'must' => [
                            'terms' => [
                                'field_support' => [105,106,1896,1897]
                            ],
                            'term' => [
                                'title' => ["le jeu de la dame"]
                            ]
                        ]

                     ]
                ]
            ]
        ]
    ]
];

我不明白为什么它不起作用。 有人能帮助我吗?感谢

1 个答案:

答案 0 :(得分:0)

您需要使用其他关联数组包围termsterm查询,如下所示:

$searchParams = [
    'body' => [
        "from"=> 0,
        "size"=> 30000,
        'query' => [
            'filtered'=> [
                'filter' => [
                    'bool' => [
                        'must' => [
                           [
                            'terms' => [
                                'field_support' => [105,106,1896,1897]
                            ]
                           ],
                           [
                            'term' => [
                                'title' => ["le jeu de la dame"]
                            ]
                           ]
                        ]

                     ]
                ]
            ]
        ]
    ]
];

<强>更新

变体match

$searchParams = [
    'body' => [
        "from"=> 0,
        "size"=> 30000,
        'query' => [
            'filtered'=> [
                'query' => [
                    'match' => [
                        'title' => ["le jeu de la dame"]
                    ]
                ],
                'filter' => [
                    'terms' => [
                        'field_support' => [105,106,1896,1897]
                    ]
                ]
            ]
        ]
    ]
];