Any chance to get rid of this query_string?

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 :slight_smile:

--
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.
For more options, visit https://groups.google.com/d/optout.

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 :slight_smile:

--
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.

hey vinneth,

thx for your answer.
but this approach doesn't work.

"viewableIDs" and "public" field are only available on my post type

so this filter would swallow all my groups and accounts.

i tried it with

"must": [
{
"term": {
"post.viewableIDs": 1
}
},
{
"term": {
"post.public": true
}
}
]

but this also does not only filter the post field.

i guess i have to create a "public" field for account and group and change
"must" to "should" ?

Am Freitag, 30. Januar 2015 06:23:13 UTC+1 schrieb vineeth mohan:

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, <menschg...@googlemail.com <javascript:>

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 :slight_smile:

--
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 elasticsearc...@googlegroups.com <javascript:>.
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/1eea7b20-16c6-4281-ba66-b6e1b5e392c5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.