1

I've been messing around with this for a while but can't get it right. I've tried several different ways of displaying this query. For example, I've made each param inside of bool a key instead of an array element. As it is now it's an array element. Either way ES doesn't seem to like it. What would be the proper format for the following query?

What it's supposed to do:

This is PHP. The should query is either in between two dates and must have the status ended OR it must start at one date and the status cannot be ended.

                      [
                            'index' => 'quotes',
                            'type' => 'title',
                            'body' => [
                            'query' => [
                                "function_score" => [
                                    'query' => [
                                    'bool' => [
                                        'filter' => [
                                            ["range"  => ["number_of_quotes" => ["gt" => 0]]],
                                            ["exists" => ["field" => "vote-average"]],
                                            ["exists" =>["field" => "first-air-date"]],
                                            ["exists" =>["field" => "last-air-date"]],

                                        ],
                                        'should' => [
                                            ['bool' => [
                                                ["range" => ["first-air-date" => [
                                                        "gte" => "$begin",
                                                        "format" => "yyyy"
                                                    ],
                                                    ["last-air-date" => [
                                                        "lte" => $begin,
                                                        "format" => "yyyy"
                                                    ]],
                                                ]],
                                                ["must" => [
                                                    "match" => [
                                                        "status" => "Ended"
                                                    ]
                                                ]
                                            ]], 

                                        ],
                                        ['bool' => [
                                            ["range" => ["first-air-date" => [
                                                "gte" => "$begin",
                                                 "format" => "yyyy"
                                            ]]],
                                            ["must_not" => [
                                                "match" => [
                                                    "status" => "Ended"
                                                ]
                                            ]
                                        ]], 

                                    ]]],
                                    ]
                                ],
                            ],  
                        ],       
                        "from" => (int) $skip,
                        "size" => (int) $take,
                        ];
Quesofat
  • 1,493
  • 2
  • 21
  • 49
  • This is PHP.... The should query is either in between two dates and must have the status ended OR it must start at one date and the status cannot be ended. – Quesofat Dec 07 '18 at 20:45
  • 1
    @JayBlanchard It's definitely not a duplicate. – Quesofat Dec 07 '18 at 20:46
  • 1
    @JayBlanchard The same errors in elastic search still aren't the same errors thrown in other code bases. It's not a type error. Why don't you focus on helping people instead of moderating them? And further more, what more evidence do you want? There isn't a way for me to spin up an ES instance, plug in some data and give you a complete example... I'm not sure you know what elastic search is.... – Quesofat Dec 07 '18 at 20:51
  • 1
    Furthermore, it's definitely not a nested query.... A nested query is something entirely different in ES. Like searching object within an object not nesting DSL.... – Quesofat Dec 07 '18 at 20:54

0 Answers0