Query_string not match with Should Condions

My intention is to find a word in all documents which have this condions:
("type" => "Faq") OR ("type" => "NormativeDoc") OR ("type" => "Document" AND "profile_id_document" => X).

I tried this but it doesn't work:

$params = [
            'index' => global_index,
            'type' =>  'documento_globale',
            'body' => [
                'query' => [
                    'bool' => [
                        'must' => [
                                'query_string' => [
                                    'query' => "{$keyword}"
                                ]
                        ],
                        "should" => [
                            [
                             "match" => [
                                [
                                    "profile_id_document" => 32,
                                    "type" => "Document"
                                ]
                             ]
                            ],
                            [
                             "match" => [
                                "type" => "Faq"
                             ]
                            ],
                            [
                             "match" => [
                                "type" => "NormativeDocument"
                             ]
                            ]
                        ],
                    ]
                ]
            ]
        ];

it doesn't seems so difficult to do in SQL, but it seems impossible in elasticsearch. Can Anyone help me?

should clauses are just optional extras when paired with must clauses. They add to the score.

If you need true OR logic you need bool query with only a should section. Your query in pseudocode would be:

 bool
     should 
            type : faq
            type : normativeDoc
            bool
                   must
                        type : Document
                        profile_id_document : X
1 Like

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