Hi,
I have a question with regards to a complex OR and AND query. I have
been googling it all day with no luck.
Here is a sample data for an index called "contacts".
company_id, contact_id, contact_type name
1 6 Company Amazon…..
6 14 Person
Amazon…..
1 14 Person
Amazon…..
6 15 Person
Amazon…..
1 15 Person
Amazon…..
6 16 Person
Amazon…..
1 16 Person
Amazon…..
Now say I want to query for name with "amazon*" but filtered on say
(company_id = 6 AND contact_id = 14)
OR
(contact_type = "Company")
i.e. this should return
1 6 Company Amazon…..
6 14 Person
Amazon…..
this is what my code looks like:
curl -X GET "http://localhost:9200/contact_contacts/_search?
pretty=true" -d '
{
"query": {
"bool": {
"should": [
{
"query_string":
{
"query":"amazon*","default_operator":"AND"
}
}
]
}
},
"filter": {
"or" : [
{
"term" : {"contact_type" : "Company::Company"}
},
{
"term" : {"contact_id" : "14", "company_id" : "6"}
}
]
}
}'
But the above returns
1 6 Company Amazon…..
6 14 Person
Amazon…..
in addition to the following which i do not want.
6 15 Person
Amazon…..
6 16 Person
Amazon…..
How would I go about constructing the filters? I am hoping you can
help me out on this one.
thank you
Prabakar Puvanathasan