gpt4 book ai didi

elasticsearch - NumberFormatException [用于输入字符串] Elasticsearch

转载 作者:行者123 更新时间:2023-12-02 23:26:57 26 4
gpt4 key购买 nike

我正在尝试将地理多边形过滤器发送到Elastic Search。它期望经/纬集为数字。但是,当我尝试通过循环进行组合时,无法创建它并不断获取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.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
]
]
]

关于elasticsearch - NumberFormatException [用于输入字符串] Elasticsearch ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41693128/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com