# Elasticsearch DSL queries : how to handle search if some documents doesn't have the specific field

**URL:** https://discuss.elastic.co/t/elasticsearch-dsl-queries-how-to-handle-search-if-some-documents-doesnt-have-the-specific-field/101826
**Category:** Elasticsearch
**Created:** [September 26, 2017, 10:30am UTC](https://discuss.elastic.co/t/elasticsearch-dsl-queries-how-to-handle-search-if-some-documents-doesnt-have-the-specific-field/101826 "2017-09-26T10:30:12Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![maralbe](https://avatars.discourse-cdn.com/v4/letter/m/6f9a4e/32.png) [@maralbe](https://discuss.elastic.co/u/maralbe)
#### Post date: [September 26, 2017, 10:30am UTC](https://discuss.elastic.co/t/elasticsearch-dsl-queries-how-to-handle-search-if-some-documents-doesnt-have-the-specific-field/101826/1 "2017-09-26T10:30:12Z")

</div>

Hi,  
I have documents that have not same structure, I mean some of my documents have some fields that other doesn't, so I want to search in those fields that may or may not exists..  
I wrote a bool query with filter and must\_not combination, but it doesn't return to me anything! I Wrote another query like that on another field that almost exists and the results are what I expected.. so I know the query is ok! but if you know another solution can share that with me?  
thanks with advanced..

PS: this is part of my query:

```
body: [
   "query" => [
      "bool" => [
        "must" => [
          [
              "query_string" => [
              "query" => "sales"
              "boost" => 1
           ]
        ]
      ]
      "must_not" => []
      "filter" => [
        [
            "bool" => [
               "must_not" => [
                  ["term" => ["professional_experience.location_id" => 1]]
               ]
            ]
        ],
        [
           "bool" => [
               "must_not" => [
                  ["term" => ["educations.location_id" => 1]]
              ]
           ]
         ]
      ]
    ]
  ]
]
```

---

<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: [October 24, 2017, 10:30am UTC](https://discuss.elastic.co/t/elasticsearch-dsl-queries-how-to-handle-search-if-some-documents-doesnt-have-the-specific-field/101826/2 "2017-10-24T10:30:16Z")

</div>

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