user6839326
user6839326

Reputation:

Dealing with must/should in Elasticsearch

I am a beginner in Elasticsearch and I have today a problem in making a "multi-AND-OR" query. I have a SQL query that I need to transform in Elastic :

WHERE host_id = 999 AND psh_pid = 444 AND psh_ppid = 777
OR    host_id = 111 AND psh_pid = 666 AND psh_ppid = 333
OR    ..... (indefinitely)

Did I am forced to do it with several queries ?

Upvotes: 1

Views: 213

Answers (1)

user6839326
user6839326

Reputation:

I am completely sorry but I think I've found the solution by myself :3

If someone need this, I put it here !

{"from":0,
"size":100,
"query":
    {"bool":
        {"should":
            [{"bool":
                {"must":
                    [{"query_string":
                        {"query":"801","fields":["host_id"]}},
                    {"query_string":
                        {"query":"1","fields":["psh_pid"]}},
                    {"query_string":
                        {"query":"0","fields":["psh_ppid"]}}
                ]}
            },{"bool":
                {"must":
                    [{"query_string":
                        {"query":"801","fields":["host_id"]}},
                    {"query_string":
                        {"query":"2621550","fields":["psh_pid"]}},
                    {"query_string":
                        {"query":"1","fields":["psh_ppid"]}}
                    ]
                }}
            ]
        }
    }
}

Upvotes: 1

Related Questions