Elasticsearch nested objects MUST bool filter


(Adam Krajcs) #1

Hi,

I've the following nested index structure:
"sector_parametric": [
{
"sector": [
"2"
],
"experience": 1.7,
"adv_business_sector_id": "637"
},
{
"sector": [
"1",
"2",
"10003"
],
"experience": 2.7,
"adv_business_sector_id": "642"
}]

I want to show the documents with the sector value is 1 AND 2, BUT not necessarily in one nested object, so
the following document would be perfect
"sector_parametric": [
{
"sector": [
"1"
],
"experience": 1.7,
"adv_business_sector_id": "637"
},
{
"sector": [
"2",
"10003"
],
"experience": 2.7,
"adv_business_sector_id": "642"
}]

If I filter with the following query, there will be only documents where one nested sector object contains BOTH 1 AND 2:
[query] => Array
(
[bool] => Array
(
[filter] => Array
(
[bool] => Array
(
[must] => Array
(
[0] => Array
(
[nested] => Array
(
[path] => sector_parametric
[query] => Array
(
[bool] => Array
(
[must] => Array
(
[0] => Array
(
[term] => Array
(
[sector_parametric.sector] => 1
)

                                                                                            )

                                                                                    )

                                                                            )

                                                                    )

                                                            )

                                                    )

                                                [1] => Array
                                                    (
                                                        [nested] => Array
                                                            (
                                                                [path] => sector_parametric
                                                                [query] => Array
                                                                    (
                                                                        [bool] => Array
                                                                            (
                                                                                [must] => Array
                                                                                    (
                                                                                        [0] => Array
                                                                                            (
                                                                                                [term] => Array
                                                                                                    (
                                                                                                        [sector_parametric.sector] => 2
                                                                                                    )

                                                                                            )

                                                                                    )

                                                                            )

                                                                    )

                                                            )

                                                    )

                                            )

                                    )

                            )

                    )

            )

(Tobias O.) #2

I dont have an answer to your question but would you be so kind to format your code with an indent of 4 spaces like the last part accidentally is so future onlookers can and understand it better?


(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.