Reputation: 43
I would like to use elastica to filter following by multiple matches inside the category:
Something like:
(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
}
]
I have tried:
$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();
Upvotes: 0
Views: 598
Reputation: 16335
Just translated your boolean clauses into JSON format which can be passed directly to elasticsearch query. I think this should work.
{
"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"
}
}
}
]
}
}
}
}
]
}
}
}
Upvotes: 1