How to find all docs where field_a === val1 and field_b === val2?

So far I can find all docs where field_a == val1. But I can't figure out
how to add the second condition.

I've been trying this with the elasticsearch php library.

    $postParams = [];
    $postParams['index'] = 'myindex';
    $postParams['type']  = 'mytype';
    $postParams['body'] = '{
        "query" : {
            "match" : {
                "status" : {"query" => "unread", "operator" : "and" },
                "priority" : {"query" => 5, "operator" : "and" }
            }
        }
    }';
    $results = $esclient->search($postParams);

I've also tried:

$postParams['body'] = '{
"query" : {
"match" : {
"status" : {"query" => "unread", "operator" : "and" }
},
"match" : {
"priority" : {"query" => 5, "operator" : "and" }
}
}
}';

And a bunch of other ways that I didn't document.

So, what am I missing?

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/3c6ad98b-dbfe-42b0-bddf-4a47e0aec368%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David,

This is what I use. I hope it helps.

{
"bool" : {
"must" : [ {
"match" : {
"field_a" : {
"query" : "val1",
"type" : "boolean"
}
}
}, {
"match" : {
"field_b" : {
"query" : "val2",
"type" : "boolean"
}
}
} ]
}
}

Brian

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/64aa8c31-2002-4432-bd7f-5c9bba3184da%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

By the way, David, the full query follows:

{
"from" : 0,
"size" : 20,
"timeout" : 60000,
"query" : {
"bool" : {
"must" : [ {
"match" : {
"field_a" : {
"query" : "val1",
"type" : "boolean"
}
}
}, {
"match" : {
"field_b" : {
"query" : "val2",
"type" : "boolean"
}
}
} ]
}
},
"version" : true,
"explain" : false,
"fields" : [ "_ttl", "_source" ]
}

Also note that since the _ttl field is being requested (always), then the
_source must also be asked for explicitly. If you don't ask for any fields,
_source is returned by default. But if you ask for one or more fields
explicitly, then you must also ask for _source or it won't be returned.

Brian

On Wednesday, January 14, 2015 at 6:31:29 PM UTC-5, Brian wrote:

David,

This is what I use. I hope it helps.

{
"bool" : {
"must" : [ {
"match" : {
"field_a" : {
"query" : "val1",
"type" : "boolean"
}
}
}, {
"match" : {
"field_b" : {
"query" : "val2",
"type" : "boolean"
}
}
} ]
}
}

Brian

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/ee28beb0-4ee6-463d-8891-a2d158e00934%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thanks! I was thinking a bool query was something specific to fields with
boolean values. Which is why I didn't understand the bool query example in
the docs. Your posts helped me get what I wanted. :slight_smile:

On Wednesday, January 14, 2015 at 3:34:05 PM UTC-8, Brian wrote:

By the way, David, the full query follows:

{
"from" : 0,
"size" : 20,
"timeout" : 60000,
"query" : {
"bool" : {
"must" : [ {
"match" : {
"field_a" : {
"query" : "val1",
"type" : "boolean"
}
}
}, {
"match" : {
"field_b" : {
"query" : "val2",
"type" : "boolean"
}
}
} ]
}
},
"version" : true,
"explain" : false,
"fields" : [ "_ttl", "_source" ]
}

Also note that since the _ttl field is being requested (always), then the
_source must also be asked for explicitly. If you don't ask for any fields,
_source is returned by default. But if you ask for one or more fields
explicitly, then you must also ask for _source or it won't be returned.

Brian

On Wednesday, January 14, 2015 at 6:31:29 PM UTC-5, Brian wrote:

David,

This is what I use. I hope it helps.

{
"bool" : {
"must" : [ {
"match" : {
"field_a" : {
"query" : "val1",
"type" : "boolean"
}
}
}, {
"match" : {
"field_b" : {
"query" : "val2",
"type" : "boolean"
}
}
} ]
}
}

Brian

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/feb306b6-aa38-4eaf-a9fc-ad23be10ea4a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.