2017-01-17 42 views
0

我想将地理多边形过滤器发送到弹性搜索。它预计经纬度为数字。但是当我尝试通过循环来创建组合时,我无法创建它并不断获取NumberFormatException [对于输入字符串。这是我正在尝试的代码。NumberFormatException [对于输入字符串]弹性搜索

$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.757580, 52.26340833563143], 
            [-113.757580, 52.28405766436857], 
            [-113.73371740878373, 52.298658944745554], 
            [-113.69997059121626, 52.298658944745554] 
           ] 
          ] 
         ] 
        ] 
       ] 
      ] 
     ] 
    ]; 

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

感谢

回答

0

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

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

不,它没有工作.... – Omicans

+0

这是我收到的错误错误:parse_exception:预期的数值\ n – Omicans

+0

您可能希望打印'$ points_to_pass'并查看这些值是否为数字,据我所知它们是字符串。您可能需要将'$ splits [i]'转换为数字 – Val

相关问题