Elasticsearch Nested Queries

Complete newbie here.

I have some documents stored in ES, where each document looks like:
{

    "_index": "index1",

    "_type": "type1",

    "_id": "1_1",
    
"_score": 2,

    "_source": {

      "agencyid": 1,

      "documentId": 1,

      "entityType": "entityType1",

      "documents": [

        {

          "DocumentId": 1,

          "DocumentType": "Dt1",

          "text": "This is DT1"

        }

      ],

      "minutesEntity": {

        "minutesID": 15,

        "CancelNotice": "CancelNotice1a",

        "FormalName": "FormalName1a",

        "TypeName": "TypeName1a"

      },
    }

Using DSL and ultimately NEST, I would like to return all documents where the following nested fields are matched:

  • DocumentId
  • FormalName

Thank you.

Hi,

You can try the following query, the query might change if you have some different mapping .

GET test/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match" : {
            "documents.DocumentId": 1
          } 
        },
        {
          "match": {
            "minutesEntity.FormalName": "FormalName1a"
          }
        }
      ]
    }
  }
}

If you want more information you can find at: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.