Hello ,
You need to use a bool query
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html
or a filtered query
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-filtered-query.html
for this purpose.
In bool , you can mix and match any number of queries and implement the
boolean logic there.
Filtered query gives you provision to add a query part and a filter part.
As the additional conditions are filters which gives a Yes or No match
rather than score , i feel it would be best to offload them to filters
So below would be the best -
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"term": {
"viewableIDs": 1
}
},
{
"term": {
"public": true
}
}
]
}
},
"query": {
"multi_match": {
"query": "SearchQuery",
"fields": [
"account.name",
"group.title",
"post.content"
]
}
}
}
}
}
Thanks
Vineeth Mohan,
Elasticsearch consultant,
qbox.io ( Elasticsearch service provider http://qbox.io)
On Thu, Jan 29, 2015 at 10:32 PM, menschguenther@googlemail.com wrote:
Hi all,
i need to write a search query which collects documents from 3 types in my
index.
basically i would use a multi_match like
{
"multi_match" : {
"query": "SearchQuery",
"fields": [ "account.name", "group.title", "post.content" ]
}
}
but the result of this query needs to be filtered by an additional
"ID-field" and "public-field" which should only affect the post
documents!.
so i created a string query like:
{
"query_string": {
"query": "(content:SearchQuery AND (viewableIDs:1 OR public:true)) OR (title:SearchQuery) OR (name:SearchQuery)"
}
}
which does the job. (show only post documents which belongs to User with ID 1 or is public)
is it possible to create a multi_match query or any other kind of query to achieve this result?
thx
--
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/cc8a1bdc-156e-4124-9aac-d055cf903ac1%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/cc8a1bdc-156e-4124-9aac-d055cf903ac1%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.
--
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/CAGdPd5mu9P3_Z5t7Spbfr994poBUzfO7b7t27nnvDzQJ8vRSJg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.