在elasticsearch中如何在csv字符串字段

时间:2017-02-14 11:40:41

标签: php elasticsearch

我是elasticsearch的新手,我有产品索引,其中类别在一个字段中存储为csv字符串。我正在使用php客户端,我当前的搜索代码看起来像

$params = [
            "index" => "products",
            "type" => "product",
            "body" => [
                "size" => "5",
                "query" => [
                    "function_score" => [
                        "query" => [
                            "bool" => [
                                "must" => [
                                    "query_string" => [
                                        "fields" => ["category", "sub_category", "website", "services_offered", "keyword", "locations", "info"],
                                          "query" => $keyword."*"
                                    ]
                                ],
                                "filter" => [
                                    "term"=> ["is_active"=>1]
                                ]
                            ]
                        ],
                        "functions" => [
                                        [
                                            "field_value_factor" => ["field" => "rating", "modifier" => "none", "factor" => 1]
                                        ],
                                        [
                                            "field_value_factor" => ["field" => "reviews","modifier" => "log1p","factor" => 2]
                                        ]
                                    ]
                    ]
                ]
            ]
        ];
        $results = $this->elasticclient->search($params);

我尝试修改filter数组,如

"filter" => [
                                    "term"=> ["is_active"=>1],
                                        "wildcard" => ["category"=>$category]
                                ]

但我收到malformed query, expected [END_OBJECT] but found [FIELD_NAME]错误。

另外在旁注中,在php客户端中,如何才能获得最终生成的调试查询?

1 个答案:

答案 0 :(得分:0)

terms过滤器不支持通配符。您可以使用regexp过滤器(Elasticsearch版本中的查询> = 2.0)。