# Translate searchSourceJSON to Query DQL

**URL:** <https://discuss.elastic.co/t/translate-searchsourcejson-to-query-dql/260847>\
**Category:** Kibana\
**Created:** [January 12, 2021, 3:21pm UTC](https://discuss.elastic.co/t/translate-searchsourcejson-to-query-dql/260847 "2021-01-12T15:21:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hyxelt](https://avatars.discourse-cdn.com/v4/letter/h/0ea827/32.png) [@hyxelt](https://discuss.elastic.co/u/hyxelt)\
**Post date:** [January 12, 2021, 3:21pm UTC](https://discuss.elastic.co/t/translate-searchsourcejson-to-query-dql/260847/1 "2021-01-12T15:21:22Z")

</div>

I am trying to convert searchSourceJSON attribute of savedObject in DQL. But I haven't found a way to do it. The idea is to be able to execute the query that is stored in the object and execute it directly in ElasticSearch.

Perhaps the buildEsQuery could be the key. But I am not an expert in Kibana and for me it is complicated. I've been at it for several days.

someone could help me? Thanks a you

KQL

```
 {
  "highlightAll": true,
  "version": true,
  "query": {
    "query": "",
    "language": "kuery"
  },
  "filter": [
    {
      "meta": {
        "alias": null,
        "negate": false,
        "disabled": false,
        "type": "phrase",
        "key": "category.keyword",
        "params": {
          "query": "Women's Accessories"
        },
        "indexRefName": "kibanaSavedObjectMeta.searchSourceJSON.filter[0].meta.index"
      },
      "query": {
        "match_phrase": {
          "category.keyword": "Women's Accessories"
        }
      },
      "$state": {
        "store": "appState"
      }
    }
  ],
  "indexRefName": "kibanaSavedObjectMeta.searchSourceJSON.index"
}

```

DSL

```
{
  "query": {
"bool": {
  "must": [],
  "filter": [
    {
      "match_all": {}
    },
    {
      "match_phrase": {
        "category.keyword": "Women's Accessories"
      }
    }
  ],
  "should": [],
  "must_not": []
}
  }
}
```

---

<div class="post-metadata">

**Author:** ![ppisljar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppisljar/32/11588_2.png) [@ppisljar](https://discuss.elastic.co/u/ppisljar)\
**Post date:** [January 12, 2021, 4:00pm UTC](https://discuss.elastic.co/t/translate-searchsourcejson-to-query-dql/260847/2 "2021-01-12T16:00:01Z")

</div>

Hello,

first a few warnings 🙂 relying on saved object format (outside of app owning that saved object) is not safe as that might change in any version. To do the conversion you first need to parse json, extract the searchsourceFields from it and pass that to `data.search.searchSource.create()`. Now you have a searchsource instance and you can call `flatten()` on it to convert it to elasticsearch DSL.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 9, 2021, 4:00pm UTC](https://discuss.elastic.co/t/translate-searchsourcejson-to-query-dql/260847/3 "2021-02-09T16:00:04Z")

</div>

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