ES query question

Hello,

I have indexed the following:

_index: community_id_113
_type: question
group_id : 123
user_id: 2
message: "Hello, how are you?"

_index: community_id_113
_type:question
group_id:143
user_id:5
message: "How is it going?"

I want to perform a search for the keyword "How", but I only want to search
within messages with user_id: 5 and and group_id: 143. How do I do this?

--

Use filtered queries and filter your "how" query with a bool filter :
Must termFilter group_id : 143
Must termFilter user_id : 5

HTH
David

Le 16 août 2012 à 20:59, msya mohitsya@gmail.com a écrit :

Hello,

I have indexed the following:

_index: community_id_113
_type: question
group_id : 123
user_id: 2
message: "Hello, how are you?"

_index: community_id_113
_type:question
group_id:143
user_id:5
message: "How is it going?"

I want to perform a search for the keyword "How", but I only want to search within messages with user_id: 5 and and group_id: 143. How do I do this?

--

--

Thank you for replying to my message. I constructed the following query:

curl -XGET 'localhost:9200/community_id_1113/question/_search?pretty=true'
-d '
{"query" : {
"filtered" : {
"query" : {
"queryString" : {
"default_field": "message",
"query" : "how"
}
},
"filter" : {
"bool" : {
"must" : [
{
"term" : { "user_id" : "143" }
},
{
"term" : { "group_id" : "5" }
}
]
}
}
}
}
}'

This gave me the right results, however I haven't index a large amount of
data. Would this query be right? In terms of performance, would it run slow
for a large indexed dataset?

On Thursday, August 16, 2012 4:15:58 PM UTC-4, David Pilato wrote:

Use filtered queries and filter your "how" query with a bool filter :
Must termFilter group_id : 143
Must termFilter user_id : 5

Elasticsearch Platform — Find real-time answers at scale | Elastic
Elasticsearch Platform — Find real-time answers at scale | Elastic
Elasticsearch Platform — Find real-time answers at scale | Elastic

HTH
David

Le 16 août 2012 à 20:59, msya <mohi...@gmail.com <javascript:>> a écrit :

Hello,

I have indexed the following:

_index: community_id_113
_type: question
group_id : 123
user_id: 2
message: "Hello, how are you?"

_index: community_id_113
_type:question
group_id:143
user_id:5
message: "How is it going?"

I want to perform a search for the keyword "How", but I only want to
search within messages with user_id: 5 and and group_id: 143. How do I do
this?

--

--

IMHO the query looks nice and it will be fast on large dataset.

You will have to perform some tests and if needed adjust the number of shards and replica. But query looks ok like this.

My 2 cents.

David :wink:
Twitter : @dadoonet / @elasticsearchfr

Le 17 août 2012 à 03:21, msya mohitsya@gmail.com a écrit :

Thank you for replying to my message. I constructed the following query:

curl -XGET 'localhost:9200/community_id_1113/question/_search?pretty=true' -d '
{"query" : {
"filtered" : {
"query" : {
"queryString" : {
"default_field": "message",
"query" : "how"
}
},
"filter" : {
"bool" : {
"must" : [
{
"term" : { "user_id" : "143" }
},
{
"term" : { "group_id" : "5" }
}
]
}
}
}
}
}'

This gave me the right results, however I haven't index a large amount of data. Would this query be right? In terms of performance, would it run slow for a large indexed dataset?

On Thursday, August 16, 2012 4:15:58 PM UTC-4, David Pilato wrote:
Use filtered queries and filter your "how" query with a bool filter :
Must termFilter group_id : 143
Must termFilter user_id : 5

Elasticsearch Platform — Find real-time answers at scale | Elastic
Elasticsearch Platform — Find real-time answers at scale | Elastic
Elasticsearch Platform — Find real-time answers at scale | Elastic

HTH
David

Le 16 août 2012 à 20:59, msya mohi...@gmail.com a écrit :

Hello,

I have indexed the following:

_index: community_id_113
_type: question
group_id : 123
user_id: 2
message: "Hello, how are you?"

_index: community_id_113
_type:question
group_id:143
user_id:5
message: "How is it going?"

I want to perform a search for the keyword "How", but I only want to search within messages with user_id: 5 and and group_id: 143. How do I do this?

--

--

--

How to construct a query to search for user_id: 5 , group_id: 143 ,
message is "how" . I mean it should return results based on all the field
values given .
If possible suggest me the code snippet using java api.

Thanks,
Naveen Vishwanatham.

On Thursday, August 16, 2012 8:53:37 PM UTC-5, David Pilato wrote:

IMHO the query looks nice and it will be fast on large dataset.

You will have to perform some tests and if needed adjust the number of
shards and replica. But query looks ok like this.

My 2 cents.

David :wink:
Twitter : @dadoonet / @elasticsearchfr

Le 17 août 2012 à 03:21, msya <mohi...@gmail.com <javascript:>> a écrit :

Thank you for replying to my message. I constructed the following
query:

curl -XGET 'localhost:9200/community_id_1113/question/_search?pretty=true'
-d '
{"query" : {
"filtered" : {
"query" : {
"queryString" : {
"default_field": "message",
"query" : "how"
}
},
"filter" : {
"bool" : {
"must" : [
{
"term" : { "user_id" : "143" }
},
{
"term" : { "group_id" : "5" }
}
]
}
}
}
}
}'

This gave me the right results, however I haven't index a large amount of
data. Would this query be right? In terms of performance, would it run slow
for a large indexed dataset?

On Thursday, August 16, 2012 4:15:58 PM UTC-4, David Pilato wrote:

Use filtered queries and filter your "how" query with a bool filter :
Must termFilter group_id : 143
Must termFilter user_id : 5

Elasticsearch Platform — Find real-time answers at scale | Elastic
Elasticsearch Platform — Find real-time answers at scale | Elastic
Elasticsearch Platform — Find real-time answers at scale | Elastic

HTH
David

Le 16 août 2012 à 20:59, msya mohi...@gmail.com a écrit :

Hello,

I have indexed the following:

_index: community_id_113
_type: question
group_id : 123
user_id: 2
message: "Hello, how are you?"

_index: community_id_113
_type:question
group_id:143
user_id:5
message: "How is it going?"

I want to perform a search for the keyword "How", but I only want to
search within messages with user_id: 5 and and group_id: 143. How do I do
this?

--

--

--