gpt4 book ai didi

php - 带有has_child的PHP ElasticSearch复合查询

转载 作者:行者123 更新时间:2023-12-03 01:43:46 24 4
gpt4 key购买 nike

当我向Elasticsearch查询特定制造商的产品时,此方法有效:

  $params = ['index' => 'products',
'type' => 'product',
'body' => ['query' =>
['match' => ['manufacturers_id' => $query],],
],
];

但是,当我还想在商品为银色的情况下添加商品时,我将其作为子记录添加到商品记录中,这时出现语法错误:
 $params = ['index' => 'products',
'type' => 'product',
'body' => ['query' =>
['match' => ['manufacturers_id' => $query],],
['query' =>
['has_child' =>
['type' => 'attributes',
['query' =>
['color' => 'Silver'],],
],
],
],
],
];

错误是
{
"error": {
"col": 49,
"line": 1,
"reason": "Unknown key for a START_OBJECT in [0].",
"root_cause": [
{
"col": 49,
"line": 1,
"reason": "Unknown key for a START_OBJECT in [0].",
"type": "parsing_exception"
}
],
"type": "parsing_exception"
},
"status": 400
}

也试过了
  $params = ['index' => 'products',
'type' => 'product',
'body' => ["query"=> [
"match"=> [
"manufacturers_id"=> [11]
],
"has_child"=> [
"type"=> "attributes",
"query"=> [
"match"=> [
"color"=> "silver"
],
],
],
],
],
];

我得到“无法在1:39的START_ARRAY上获取文本”。

最佳答案

试试这个:

"query"=> [
"match"=> [
"manufacturers_id"=> [1,2,3]
],
"has_child"=> [
"type"=> "attributes",
"query"=> [
"match"=> [
"color"=> "silver"
]
]
]
]

我还建议您使用Sense,它是Chrome浏览器的插件,可帮助编写ES查询。
See the screenshot

关于php - 带有has_child的PHP ElasticSearch复合查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45484491/

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