【问题标题】:In elasticsearch how to filter in csv string field在elasticsearch中如何过滤csv字符串字段
【发布时间】:2017-02-14 20:08:09
【问题描述】:

我是 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 客户端中,我怎样才能获得最终生成的查询以进行调试?

【问题讨论】:

    标签: php elasticsearch


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-14
      • 2020-02-01
      相关资源
      最近更新 更多