2017-01-17 15 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] 
           ] 
          ] 
         ] 
        ] 
       ] 
      ] 
     ] 
    ]; 

$ points_to_passをElasticSearchで受け入れられる形式で変換する方法を教えてください。

おかげ

答えて

0

$points_to_passはすでに配列の配列であるので、あなたは次のように試してみてください:

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

ありません、それは動作しませんでした.... – Omicans

+0

これは私がエラーを受信したエラーです:parse_exception:数値が期待されている\ n – Omicans

+0

'$ points_to_pass'を出力して、値が数値であるかどうかを文字列であるかどうか確認することができます。 '$ splitits [i]'を数字の – Val

関連する問題