NumberFormatException [对于输入字符串]弹性搜索

时间:2017-01-17 09:14:59

标签: elasticsearch numberformatexception

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

public User GetUserFromID(int id)
{
    var user = Users.SingleOrDefault(u => u.id == id);

    if(user == null)
        throw new Exception("No user is found");

    return user;
}

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

    $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
                                ]
                            ]
                        ]
                    ]
                ]
            ]
        ]
    ];

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

感谢

1 个答案:

答案 0 :(得分:0)

由于$points_to_pass已经是一个数组数组,你应该尝试这样:

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