2017-01-17 45 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

相關問題