-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
multiple termQuery not working #179
Comments
Hi @dijadev The query is correct. But in your case it should be formed as 3 bool queries in the must operator. {
"query": {
"bool":
{
"must":[
{
"term":{"tag":"wow"}
},
{
"term":{"tag":"elasticsearch"}
},
{
"term":{"tag":"dsl"}
}
]
}
}
} |
Hi @saimaz thank you for replying! |
You query is right. The output should be like I posted. $search = new Search();
$termQueryForTag1 = new TermQuery("tag", "wow");
$termQueryForTag2 = new TermQuery("tag", "elasticsearch");
$termQueryForTag3 = new TermQuery("tag", "dsl");
$search->addQuery($termQueryForTag1);
$search->addQuery($termQueryForTag2);
$search->addQuery($termQueryForTag3);
$queryArray = $search->toArray();
echo "<pre>";json_encode($queryArray);die(); Generates: {
"query": {
"bool":
{
"must":[
{
"term":{"tag":"wow"}
},
{
"term":{"tag":"elasticsearch"}
},
{
"term":{"tag":"dsl"}
}
]
}
}
} If not, sent me more info about your env. The exact ElasticsearchDSL version 2.2.x (what is x number), your PHP version. |
I checked the code in the bundle and i found a key optional arg so i added for each query a different key as bellow and it works !
This must be fixed or mentioned in the doc. Thanks, |
It's still very interesting why key is not generated and when you add the second query it drops first. I still cannot reproduce your issue :(. The key is for case when you want to add some identifier where you later can grab that specific query from |
Ok I'll debug this as soon as i can and will keep you in touch :) |
Probably the problem is uniqid() in BoolQuery where he is assigning the key if not exists. I have the same problem on my local machine(xampp, php 7, windows 7) where microtime is just not refreshing quick enough. I solve it with hardcoded random generator
|
Thank you @puskic. The |
I agree with you. I already have it, way not to use ;). bin2hex(random_bytes(30)) will do the work. |
Hi ! I confirm what @puskic said; this problem occurs just in windows env, and disappears when I deploy to a linux machine..
It generates the same $key for the TermQuerys I added to BoolQuery
|
Fixed in v2.2.1 release |
Hi !
I am trying to execute this query but it seems that it's not supported to add multiple termQuery.
Just the laste query was token
Is it a bug or I am doing it wrongly ?
PS: I am using ElasticSearch 2.3.3 and elasticsearch-dsl 2.2.
Thanks in advance,
The text was updated successfully, but these errors were encountered: