Hi,
This query should works for you:
{
  "query": {
    "bool": {
      "should": [
        {
          "query_string": {
            "query": "ABC 2014 123",
            "default_operator": "AND",
            "fields": [
              "name",
              "year",
              "page"
            ]
          }
        },
        {
          "nested": {
            "path": "linked_docs",
            "query": {
              "query_string": {
                "query": "ABC 2014 123",
                "default_operator": "AND",
                "fields": [
                  "linked_docs.name",
                  "linked_docs.year",
                  "linked_docs.page"
                ]
              }
            }
          }
        }
      ]
    }
  }
}

Cheers, Ramy

Am Montag, 13. Oktober 2014 12:24:42 UTC+2 schrieb Michael Werner:
>
> I am pretty new to ES and have a problem that I could not yet solve using 
> the docuemntation, so any help is appreciated...
>
> I have these douments in my index:
>
> DocType1
> {
>   "id" : 1,
>   "name" : "ABC",
>   "year" : 2014,
>   "page" : 123,
>   "linked_docs" : {
>     {
>       {
>         "id" : 2,
>         "name" : "DEF",
>         "year" : 2013,
>         "page" : 111
>       },
>       {
>         "id" : 3,
>         "name" : "GHI",
>         "year" : 2012,
>         "page" : 222
>       },
>     }
>   }
> },
> {
>   "id": 12345,
>   "name" : "XYZ",
>   "year" : 2014,
>   "page" : 999,
>   "linked_docs" : { }
> }
>
> DocType2
> {
>   "id" : 98765,
>   "user" : "User 1",
>   "type" : "Test",
>   "linked_docs" : {
>     {
>       {
>         "id" : 1,
>         "name" : "ABC",
>         "year" : 2014,
>         "page" : 123
>       },
>       {
>         "id" : 2,
>         "name" : "DEF",
>         "year" : 2013,
>         "page" : 111
>       },
>     }
>   }
> },
> {
>   "id" : 4321,
>   "user" : "User 2",
>   "type" : "Test 2",
>   "linked_docs" : { }
> }
>
>
> Now I want to get all documents matching name = ABC, year = 2014, page = 
> 123 either in the main document >>> OR <<< in the linked_docs.
>
> So with the data aboce the search should deliver the following documents:
>
> - DocType1, id: 1 (matches in main document)
> - DocType2, id: 98765 (matches in linked docs)
>
> I tried with nested query but I am not getting the result as above. 
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/a701b8f1-92ab-4186-9c98-d4995e5f653b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to