Hi Everyone,
I'm here to give back to community, i spent hours looking for an answer for my problem without luck, so I decided to share my findings with you all, so we can all take a look on the mystic of elasticsearch.
My problem was very simple, but not easy as it seems:
i needed to search for a field where the fields match a keyword or it were simply blank either null
ex:
SELECT * FROM bucket1 WHERE country="canada" AND (language=en OR language=NULL)
simple right?
for my query i constructed the following:
bucket/document/_search [POST]
{
"size": 10,
"query": {
"query_string": {
"query": "country:ca AND region1:quebec AND (language:en OR -language:*)"
}
}
}
It brought me 0 (zero) results what made me think.. because when i did the split query, it broght me around 35k results
ex:
{
"size": 10,
"query": {
"query_string": {
"query": "country:ca AND region1:quebec AND (language:en)"
}
}
}
32k results
THEN
{
"size": 10,
"query": {
"query_string": {
"query": "country:ca AND region1:quebec AND (-language:*)"
}
}
}
3k results
so i decided go for different approach
{
"size": 10,
"query": {
"query_string": {
"query": "(region1:quebec AND -geo_city:* ) OR (region1:quebec AND geo_city:montreal )"
}
}
}
35K results
conclusion NOT statement is broking everything if set with an OR statement.
after that i finally did the following:
{
"size": 10,
"query": {
"query_string": {
"query": "country:ca AND region1:quebec AND ((language:en) OR (-language:*))"
}
}
}
35k results, and it was working
now im looking for a different approach to make this query more efficient, cuz the NOT statement is taking really long time to excecute, around x20 factor than without the NOT statement.
i hope to have some feedbacks on this =)
thanks in advance