0

I have data:

[
  {
    "NAME": "John Doe", 
    "CLASS":[1,10,30]
  },
  {
    "NAME": "Albert",
    "CLASS": [1,10,40]
  },
  {
    "NAME": "XINN",
    "CLASS": [10,30]
  },
  {
    "NAME": "UJANG",
    "CLASS": [1,40]
  },
  {
    "NAME": "BAMBANG",
    "CLASS": [30,40]
  }
]

I have the following query DSL:

{
  query: {
    terms: {
      class: [1,10]
    }
  }
}

and I want what will appear is:

[{"NAME": "John Doe","CLASS":[1,10,30]},{"NAME": "Albert","CLASS": [1,10,40]}]

How do I change my search to match the result?

khairul
  • 33
  • 4

1 Answers1

0

You need to combine multiple term queries in must clause.

Query

{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "CLASS": {
              "value": 1
            }
          }
        },
        {
          "term": {
            "CLASS": {
              "value": 10
            }
          }
        }
      ]
    }
  }
}

Result

"hits" : [
      {
        "_index" : "index34",
        "_type" : "_doc",
        "_id" : "2EdK6XsBP61bDf9bI3R1",
        "_score" : 2.0,
        "_source" : {
          "NAME" : "John Doe",
          "CLASS" : [
            1,
            10,
            30
          ]
        }
      },
      {
        "_index" : "index34",
        "_type" : "_doc",
        "_id" : "2UdK6XsBP61bDf9bMHT5",
        "_score" : 2.0,
        "_source" : {
          "NAME" : "Albert",
          "CLASS" : [
            1,
            10,
            40
          ]
        }
      }
    ]
jaspreet chahal
  • 8,817
  • 2
  • 11
  • 29