gpt4 book ai didi

elasticsearch - Elastica-多个 bool 查询-子查询

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

我想使用elastica过滤类别中的多个匹配项:

就像是:

(categories.name =“category-1” AND Categories.level = 0)AND(categories.name =“category-2” AND Categories.level = 1)

"title": "Test Product 1",
"categories": [
{
"id": 1,
"name": "category-1",
"title": "Category 1",
"level": 0
},
{
"id": 2,
"name": "category-2",
"title": "Category 2",
"level": 1
}
]

我努力了:
    $matchQuery = new Query\Match();
$matchQuery->setField('categories.name', 'category-1');
//I don't know how to add AND categories.level = 0

$boolQuery1 = new Bool();
$boolQuery1->addMust($matchQuery);

$results = $record->search($boolQuery1)->getResults();

最佳答案

只需将您的 bool(boolean) 子句转换为JSON格式,即可直接传递给elasticsearch查询。我认为这应该有效。

{
"query": {
"bool": {
"must": [
{
"nested": {
"path": "categories",
"query": {
"bool": {
"must": [
{
"term": {
"categories.name": {
"value": "category-1"
}
}
},
{
"term": {
"categories.level": {
"value": "0"
}
}
}
]
}
}
}
},
{
"nested": {
"path": "categories",
"query": {
"bool": {
"must": [
{
"term": {
"categories.name": {
"value": "category-2"
}
}
},
{
"term": {
"categories.level": {
"value": "1"
}
}
}
]
}
}
}
}
]
}
}
}

关于elasticsearch - Elastica-多个 bool 查询-子查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35978128/

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