Is it possible to combine some MultiSearchResponse to one SearchResponse?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Is it possible to combine some MultiSearchResponse to one SearchResponse?

Yang
Dear all,

I met a ver special use case, here is my example:
I use user's name as a value of elasticsearch index, and the document type as a value of elasticsearch type, here we go:
index: john
type: email
the example above means, here is a user who is John, and we store all his emails under type email. For easily understand, I would say there is only one field in document which is subject. Then, my data structure may like this:
index: john
type: email
documents:
_id:1, subject:BB11, create_date: 2012-05-01
_id:2, subject:BBAA, create_date: 2012-02-18
_id:3, subject:BB12, create_date: 2012-06-07
_id:4, subject:CC11, create_date: 2012-01-05
 
Then, another user came here with his data: 
index: harry
type: essay
documents:
_id:a, title: AACC, create_date: 2012-03-08 
_id:b, title: BBCC, create_date: 2012-07-01
_id:c, title: DD11, create_date: 2012-01-16
_id:d, title: BB11, create_date: 2012-02-01

I rise 2 search requests for John and Harry separately like:
SearchResponse searchResponseForJohn = getSearchRequestBuilder().index("john").type("email").query(generateQuery("bb")).execute().actionGet(); //3 records are returned: _id=1, 2, 3
 
SearchResponse searchResponseForHarry = getSearchRequestBuilder().index("harry").type("essay").query(generateQuery("cc")).execute().actionGet(); //2 records are returned: _id=a, b

After I got the two searchResponse, I wanted to display these 5 records in one page, but I cannot order these 5 records by create_date, because they are in two search responses. You may say that I could write my code like this:
SearchResponse searchResponseForJohnAndHarry = getSearchRequestBuilder().index("
john", "harry").type("email", "essay").query(generateQuery("bb or cc")).execute().actionGet(); //but 7 records are returned: _id=1, 2, 3, b, d, 4, a, b
 
See, the result is not what I want. Then I found a function "Multi Search", but after I gave a quick try, it seems it's the same as I send 2 separate search request. I got an MultiSearchResponse with two search response in it.

For some other reasons, I do have to send 2 search request,  no matter request one by one or using MultiSearchRequest. I'm wondering, is there a way that I can combine all the search result records and make them ordered by create_date?
 
At last, THANK YOU VERY MUCH for reading all my boring content, I APPRECIATE~

best,

--
YANG
 
 

Reply | Threaded
Open this post in threaded view
|

Re: Is it possible to combine some MultiSearchResponse to one SearchResponse?

kimchy
Administrator
If you want order between the two search responses, then it needs to be a single search request. The mulit search API simply executes several search requests and each one has its own search response.

On Wed, Jul 18, 2012 at 9:14 AM, Yang <[hidden email]> wrote:
Dear all,

I met a ver special use case, here is my example:
I use user's name as a value of elasticsearch index, and the document type as a value of elasticsearch type, here we go:
index: john
type: email
the example above means, here is a user who is John, and we store all his emails under type email. For easily understand, I would say there is only one field in document which is subject. Then, my data structure may like this:
index: john
type: email
documents:
_id:1, subject:BB11, create_date: 2012-05-01
_id:2, subject:BBAA, create_date: 2012-02-18
_id:3, subject:BB12, create_date: 2012-06-07
_id:4, subject:CC11, create_date: 2012-01-05
 
Then, another user came here with his data: 
index: harry
type: essay
documents:
_id:a, title: AACC, create_date: 2012-03-08 
_id:b, title: BBCC, create_date: 2012-07-01
_id:c, title: DD11, create_date: 2012-01-16
_id:d, title: BB11, create_date: 2012-02-01

I rise 2 search requests for John and Harry separately like:
SearchResponse searchResponseForJohn = getSearchRequestBuilder().index("john").type("email").query(generateQuery("bb")).execute().actionGet(); //3 records are returned: _id=1, 2, 3
 
SearchResponse searchResponseForHarry = getSearchRequestBuilder().index("harry").type("essay").query(generateQuery("cc")).execute().actionGet(); //2 records are returned: _id=a, b

After I got the two searchResponse, I wanted to display these 5 records in one page, but I cannot order these 5 records by create_date, because they are in two search responses. You may say that I could write my code like this:
SearchResponse searchResponseForJohnAndHarry = getSearchRequestBuilder().index("
john", "harry").type("email", "essay").query(generateQuery("bb or cc")).execute().actionGet(); //but 7 records are returned: _id=1, 2, 3, b, d, 4, a, b
 
See, the result is not what I want. Then I found a function "Multi Search", but after I gave a quick try, it seems it's the same as I send 2 separate search request. I got an MultiSearchResponse with two search response in it.

For some other reasons, I do have to send 2 search request,  no matter request one by one or using MultiSearchRequest. I'm wondering, is there a way that I can combine all the search result records and make them ordered by create_date?
 
At last, THANK YOU VERY MUCH for reading all my boring content, I APPRECIATE~

best,

--
YANG
 
 


Reply | Threaded
Open this post in threaded view
|

Re: Is it possible to combine some MultiSearchResponse to one SearchResponse?

Yang
So I assume no matter I use "Multi Search Request" or not, there is no way to satisfy the requirement I mentioned above, right?

If it is, I may need to focus on other things.

On Thursday, July 19, 2012 4:39:41 AM UTC+8, kimchy wrote:
If you want order between the two search responses, then it needs to be a single search request. The mulit search API simply executes several search requests and each one has its own search response.

On Wed, Jul 18, 2012 at 9:14 AM, Yang <[hidden email]> wrote:
Dear all,

I met a ver special use case, here is my example:
I use user's name as a value of elasticsearch index, and the document type as a value of elasticsearch type, here we go:
index: john
type: email
the example above means, here is a user who is John, and we store all his emails under type email. For easily understand, I would say there is only one field in document which is subject. Then, my data structure may like this:
index: john
type: email
documents:
_id:1, subject:BB11, create_date: 2012-05-01
_id:2, subject:BBAA, create_date: 2012-02-18
_id:3, subject:BB12, create_date: 2012-06-07
_id:4, subject:CC11, create_date: 2012-01-05
 
Then, another user came here with his data: 
index: harry
type: essay
documents:
_id:a, title: AACC, create_date: 2012-03-08 
_id:b, title: BBCC, create_date: 2012-07-01
_id:c, title: DD11, create_date: 2012-01-16
_id:d, title: BB11, create_date: 2012-02-01

I rise 2 search requests for John and Harry separately like:
SearchResponse searchResponseForJohn = getSearchRequestBuilder().index("john").type("email").query(generateQuery("bb")).execute().actionGet(); //3 records are returned: _id=1, 2, 3
 
SearchResponse searchResponseForHarry = getSearchRequestBuilder().index("harry").type("essay").query(generateQuery("cc")).execute().actionGet(); //2 records are returned: _id=a, b

After I got the two searchResponse, I wanted to display these 5 records in one page, but I cannot order these 5 records by create_date, because they are in two search responses. You may say that I could write my code like this:
SearchResponse searchResponseForJohnAndHarry = getSearchRequestBuilder().index("
john", "harry").type("email", "essay").query(generateQuery("bb or cc")).execute().actionGet(); //but 7 records are returned: _id=1, 2, 3, b, d, 4, a, b
 
See, the result is not what I want. Then I found a function "Multi Search", but after I gave a quick try, it seems it's the same as I send 2 separate search request. I got an MultiSearchResponse with two search response in it.

For some other reasons, I do have to send 2 search request,  no matter request one by one or using MultiSearchRequest. I'm wondering, is there a way that I can combine all the search result records and make them ordered by create_date?
 
At last, THANK YOU VERY MUCH for reading all my boring content, I APPRECIATE~

best,

--
YANG
 
 


Reply | Threaded
Open this post in threaded view
|

Re: Is it possible to combine some MultiSearchResponse to one SearchResponse?

Igor Motov-3
I think you can achieve this by combining several "indices queries" into a single bool query: https://gist.github.com/927ce430436ad48dd863

On Wednesday, July 18, 2012 11:54:17 PM UTC-4, Yang wrote:
So I assume no matter I use "Multi Search Request" or not, there is no way to satisfy the requirement I mentioned above, right?

If it is, I may need to focus on other things.

On Thursday, July 19, 2012 4:39:41 AM UTC+8, kimchy wrote:
If you want order between the two search responses, then it needs to be a single search request. The mulit search API simply executes several search requests and each one has its own search response.

On Wed, Jul 18, 2012 at 9:14 AM, Yang <[hidden email]> wrote:
Dear all,

I met a ver special use case, here is my example:
I use user's name as a value of elasticsearch index, and the document type as a value of elasticsearch type, here we go:
index: john
type: email
the example above means, here is a user who is John, and we store all his emails under type email. For easily understand, I would say there is only one field in document which is subject. Then, my data structure may like this:
index: john
type: email
documents:
_id:1, subject:BB11, create_date: 2012-05-01
_id:2, subject:BBAA, create_date: 2012-02-18
_id:3, subject:BB12, create_date: 2012-06-07
_id:4, subject:CC11, create_date: 2012-01-05
 
Then, another user came here with his data: 
index: harry
type: essay
documents:
_id:a, title: AACC, create_date: 2012-03-08 
_id:b, title: BBCC, create_date: 2012-07-01
_id:c, title: DD11, create_date: 2012-01-16
_id:d, title: BB11, create_date: 2012-02-01

I rise 2 search requests for John and Harry separately like:
SearchResponse searchResponseForJohn = getSearchRequestBuilder().index("john").type("email").query(generateQuery("bb")).execute().actionGet(); //3 records are returned: _id=1, 2, 3
 
SearchResponse searchResponseForHarry = getSearchRequestBuilder().index("harry").type("essay").query(generateQuery("cc")).execute().actionGet(); //2 records are returned: _id=a, b

After I got the two searchResponse, I wanted to display these 5 records in one page, but I cannot order these 5 records by create_date, because they are in two search responses. You may say that I could write my code like this:
SearchResponse searchResponseForJohnAndHarry = getSearchRequestBuilder().index("
john", "harry").type("email", "essay").query(generateQuery("bb or cc")).execute().actionGet(); //but 7 records are returned: _id=1, 2, 3, b, d, 4, a, b
 
See, the result is not what I want. Then I found a function "Multi Search", but after I gave a quick try, it seems it's the same as I send 2 separate search request. I got an MultiSearchResponse with two search response in it.

For some other reasons, I do have to send 2 search request,  no matter request one by one or using MultiSearchRequest. I'm wondering, is there a way that I can combine all the search result records and make them ordered by create_date?
 
At last, THANK YOU VERY MUCH for reading all my boring content, I APPRECIATE~

best,

--
YANG
 
 


Reply | Threaded
Open this post in threaded view
|

Re: Is it possible to combine some MultiSearchResponse to one SearchResponse?

Yang
Dear Motov,

I cannot say more thanks to you, it's really a great idea.
I'll make it work in my code and let you and other guys know the solution who meet the same problem that I met.

Again, thanks very much~

best,

On Saturday, July 21, 2012 4:00:56 AM UTC+8, Igor Motov wrote:
I think you can achieve this by combining several "indices queries" into a single bool query: https://gist.github.com/927ce430436ad48dd863

On Wednesday, July 18, 2012 11:54:17 PM UTC-4, Yang wrote:
So I assume no matter I use "Multi Search Request" or not, there is no way to satisfy the requirement I mentioned above, right?

If it is, I may need to focus on other things.

On Thursday, July 19, 2012 4:39:41 AM UTC+8, kimchy wrote:
If you want order between the two search responses, then it needs to be a single search request. The mulit search API simply executes several search requests and each one has its own search response.

On Wed, Jul 18, 2012 at 9:14 AM, Yang <[hidden email]> wrote:
Dear all,

I met a ver special use case, here is my example:
I use user's name as a value of elasticsearch index, and the document type as a value of elasticsearch type, here we go:
index: john
type: email
the example above means, here is a user who is John, and we store all his emails under type email. For easily understand, I would say there is only one field in document which is subject. Then, my data structure may like this:
index: john
type: email
documents:
_id:1, subject:BB11, create_date: 2012-05-01
_id:2, subject:BBAA, create_date: 2012-02-18
_id:3, subject:BB12, create_date: 2012-06-07
_id:4, subject:CC11, create_date: 2012-01-05
 
Then, another user came here with his data: 
index: harry
type: essay
documents:
_id:a, title: AACC, create_date: 2012-03-08 
_id:b, title: BBCC, create_date: 2012-07-01
_id:c, title: DD11, create_date: 2012-01-16
_id:d, title: BB11, create_date: 2012-02-01

I rise 2 search requests for John and Harry separately like:
SearchResponse searchResponseForJohn = getSearchRequestBuilder().index("john").type("email").query(generateQuery("bb")).execute().actionGet(); //3 records are returned: _id=1, 2, 3
 
SearchResponse searchResponseForHarry = getSearchRequestBuilder().index("harry").type("essay").query(generateQuery("cc")).execute().actionGet(); //2 records are returned: _id=a, b

After I got the two searchResponse, I wanted to display these 5 records in one page, but I cannot order these 5 records by create_date, because they are in two search responses. You may say that I could write my code like this:
SearchResponse searchResponseForJohnAndHarry = getSearchRequestBuilder().index("
john", "harry").type("email", "essay").query(generateQuery("bb or cc")).execute().actionGet(); //but 7 records are returned: _id=1, 2, 3, b, d, 4, a, b
 
See, the result is not what I want. Then I found a function "Multi Search", but after I gave a quick try, it seems it's the same as I send 2 separate search request. I got an MultiSearchResponse with two search response in it.

For some other reasons, I do have to send 2 search request,  no matter request one by one or using MultiSearchRequest. I'm wondering, is there a way that I can combine all the search result records and make them ordered by create_date?
 
At last, THANK YOU VERY MUCH for reading all my boring content, I APPRECIATE~

best,

--
YANG
 
 


Reply | Threaded
Open this post in threaded view
|

Re: elasticsearch query array

phill
In reply to this post by Yang
Several things here.
You can issue _one_ search across multiple indices.
I would not put each person's e-mails in a separate index.  I would have an index of all e-mails with a field for the owner of an e-mail.

There are also parent and child relationships that can be established between two types in the same index, but nothing you said suggests you need that yet.

-Paul

On 3/4/2013 12:25 PM, eric sanford wrote:
So I assume no matter I use "Multi Search Request" or not, there is no way to satisfy the requirement I mentioned above, right?

If it is, I may need to focus on other things.

On Thursday, July 19, 2012 4:39:41 AM UTC+8, kimchy wrote:
If you want order between the two search responses, then it needs to be a single search request. The mulit search API simply executes several search requests and each one has its own search response.

On Wed, Jul 18, 2012 at 9:14 AM, Yang <[hidden email]> wrote:
Dear all,

I met a ver special use case, here is my example:
I use user's name as a value of elasticsearch index, and the document type as a value of elasticsearch type, here we go:
index: john
type: email
the example above means, here is a user who is John, and we store all his emails under type email. For easily understand, I would say there is only one field in document which is subject. Then, my data structure may like this:
index: john
type: email
documents:
_id:1, subject:BB11, create_date: 2012-05-01
_id:2, subject:BBAA, create_date: 2012-02-18
_id:3, subject:BB12, create_date: 2012-06-07
_id:4, subject:CC11, create_date: 2012-01-05
 
Then, another user came here with his data: 
index: harry
type: essay
documents:
_id:a, title: AACC, create_date: 2012-03-08 
_id:b, title: BBCC, create_date: 2012-07-01
_id:c, title: DD11, create_date: 2012-01-16
_id:d, title: BB11, create_date: 2012-02-01

I rise 2 search requests for John and Harry separately like:
SearchResponse searchResponseForJohn = getSearchRequestBuilder().index("john").type("email").query(generateQuery("bb")).execute().actionGet(); //3 records are returned: _id=1, 2, 3
 
SearchResponse searchResponseForHarry = getSearchRequestBuilder().index("harry").type("essay").query(generateQuery("cc")).execute().actionGet(); //2 records are returned: _id=a, b

After I got the two searchResponse, I wanted to display these 5 records in one page, but I cannot order these 5 records by create_date, because they are in two search responses. You may say that I could write my code like this:
SearchResponse searchResponseForJohnAndHarry = getSearchRequestBuilder().index("
john", "harry").type("email", "essay").query(generateQuery("bb or cc")).execute().actionGet(); //but 7 records are returned: _id=1, 2, 3, b, d, 4, a, b
 
See, the result is not what I want. Then I found a function "Multi Search", but after I gave a quick try, it seems it's the same as I send 2 separate search request. I got an MultiSearchResponse with two search response in it.

For some other reasons, I do have to send 2 search request,  no matter request one by one or using MultiSearchRequest. I'm wondering, is there a way that I can combine all the search result records and make them ordered by create_date?
 
At last, THANK YOU VERY MUCH for reading all my boring content, I APPRECIATE~

best,

--
YANG
 
 



--
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 [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.