Search code examples
elasticsearchquerydsl

ElasticSearch - how to query documents by specific field in JSON field


I want to "how to query documents by specific field in JSON field?"

Index Example :

{
  "_index": "battery-2021.02.18",
  "_type": "_doc",
  "_id": "DulWt3cB6VaK5-_iGoEG",
  "_version": 1,
  "_score": null,
  "_source": {
    "@timestamp": "2021-02-18T22:50:02.125Z",
    "battery_log": {
      "battery_id": "BAT80031",
      "bms": {
        "event": {
          "fault_uvp": 0,
          "fault_dc_ocp": 0,
          "fault_switch_otp": 0,
          "warning_utp": 0,
          "fault_int_otp": 0,
          "fault_c_ocp": 0,
          "warning_module_dc_utp": 1
        }
        "etc": 0
      }
    }
  }
}

I want to query documents whose battery_log.bms.event.* equals 1.

Thank you in advance.


Solution

  • With a multi_match query, you can do that:

    POST battery-2021.02.18/_search
    {
      "query": {
        "multi_match": {
          "query": "1",
          "fields": ["battery_log.bms.event.*"]
        }
      }
    }