NumberFormatException [对于输入字符串] Elastic Search

NumberFormatException[For input string] Elastic Search

我正在尝试将地理多边形过滤器发送到 Elastic Search。它期望 lat/long 设置为数字。但是当我尝试通过循环进行组合时,我无法创建它并不断获取 NumberFormatException[For input string.这是我正在尝试的代码。

    $points = $this->input->post('points');
    $points_to_pass = array();
    foreach ($points as $point) {
        $splits = explode(",", $point);

        $points_to_pass[] = [$splits[1],$splits[0]];
    }
    $json = [
        'query' => [
            'bool' => [
                'must_not' => [
                    ['terms' => ['_id' => []]],
                    ['terms' => ['rarity' => []]]
                ],
                'must' => [
                    'range' => [
                        'disappearTime' => [
                            'gte' => 'now',
                            'lte' => 'now+1d'
                        ]
                    ]
                ],
                'filter' => [
                    ['term' => ['pokemon_id' => 16]],
                    [
                        'geo_bounding_box' => [
                            'location' => [
                                'top_left' => [
                                    'lat' => 52.280577919216356,
                                    'lon' => -113.78533601760866
                                ],
                                'bottom_right' => [
                                    'lat' => 52.26306210545918,
                                    'lon' => -113.81855249404909
                                ]
                            ]
                        ]
                    ],
                    [
                        'geo_polygon' => [
                            'location' => [
                                "points" => [
                                    $points_to_pass
                                ]
                            ]
                        ]
                    ]
                ]
            ]
        ]
    ];

而如果我输入硬编码值,它就可以完美运行。硬编码值的工作示例如下。

    $json = [
        'query' => [
            'bool' => [
                'must_not' => [
                    ['terms' => ['_id' => []]],
                    ['terms' => ['rarity' => []]]
                ],
                'must' => [
                    'range' => [
                        'disappearTime' => [
                            'gte' => 'now',
                            'lte' => 'now+1d'
                        ]
                    ]
                ],
                'filter' => [
                    ['term' => ['pokemon_id' => 16]],
                    [
                        'geo_bounding_box' => [
                            'location' => [
                                'top_left' => [
                                    'lat' => 52.280577919216356,
                                    'lon' => -113.78533601760866
                                ],
                                'bottom_right' => [
                                    'lat' => 52.26306210545918,
                                    'lon' => -113.81855249404909
                                ]
                            ]
                        ]
                    ],
                    [
                        'geo_polygon' => [
                            'location' => [
                                "points" => [
                                    [-113.78721646175813, 52.29637194474555],
                                    [-113.76335508934484, 52.281770664368565],
                                    [-113.76335508934484, 52.26112133563143],
                                    [-113.78721646175813, 52.24652005525444],
                                    [-113.82096153824187, 52.24652005525444],
                                    [-113.84482291065517, 52.26112133563143],
                                    [-113.84482291065517, 52.281770664368565],
                                    [-113.82096153824187, 52.29637194474555],
                                    [-113.78721646175813, 52.29637194474555],
                                    [-113.69997059121626, 52.298658944745554],
                                    [-113.67610798767082, 52.28405766436857],
                                    [-113.67610798767082, 52.26340833563143],
                                    [-113.69997059121626, 52.248807055254446],
                                    [-113.73371740878373, 52.248807055254446],
                                    [-113.75758001232917, 52.26340833563143],
                                    [-113.75758001232917, 52.28405766436857],
                                    [-113.73371740878373, 52.298658944745554],
                                    [-113.69997059121626, 52.298658944745554]
                                ]
                            ]
                        ]
                    ]
                ]
            ]
        ]
    ];

如何将 $points_to_pass 转换为 ElasticSearch 接受的格式。

谢谢

因为$points_to_pass已经是一个数组的数组,你应该这样尝试:

                [
                    'geo_polygon' => [
                        'location' => [
                            "points" => $points_to_pass
                        ]
                    ]
                ]