7
votes

I have 2 fields type in my index;

doc1

{
"category":"15",
"url":"http://stackoverflow.com/questions/ask"
}

doc2

  {
    "url":"http://stackoverflow.com/questions/ask"
    "requestsize":"231",
    "logdate":"22/12/2012",
    "username":"mehmetyeneryilmaz"
    }

now I need such a query that filter in same url field and returns fields both of documents:

result:

        {
        "category":"15",
        "url":"http://stackoverflow.com/questions/ask"
        "requestsize":"231",
        "logdate":"22/12/2012",
        "username":"mehmetyeneryilmaz"
        }
1
you would need to do the merging on the client side i should be simple to get the all neccessary information to do the merging from elasticsearch.keety
but there would be thousands of documents... you mean it is not possible or you don't know the way there is?user4005632
@EvaldasBuinauskas lol. if you think this way, no one can post question anymore. I need merge diffirent docs returned from query, not merge queries..user4005632
You basically just need to add a category field to your doc2? Basically, what you're asking in your other question, right?Val

1 Answers

2
votes

The results given by elasticsearch are always per document, means that if there are multiple documents satisfying your query/filter, they would always appear as a different documents in the result and never merged into a single document. Hence merging them at client side is the one option which you can use. To avoid getting complete document and just to get the relevant fields, you can use "fields" in your query.

If this is not what you need and still needs narrowing down the result from the query itself, you can use top hit aggregations. It will give you the complete list of documents under a single bucket. But it would also have source field which would contain the complete documents itself.

Try giving a read to page: https://www.elastic.co/guide/en/elasticsearch/reference/1.4/search-aggregations-metrics-top-hits-aggregation.html