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.