# How to search over all fields and return every document containing that search in elasticsearch?

**URL:** <https://discuss.elastic.co/t/how-to-search-over-all-fields-and-return-every-document-containing-that-search-in-elasticsearch/271533>\
**Category:** Elasticsearch\
**Created:** [April 28, 2021, 3:20pm UTC](https://discuss.elastic.co/t/how-to-search-over-all-fields-and-return-every-document-containing-that-search-in-elasticsearch/271533 "2021-04-28T15:20:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sander\_Marx](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sander_marx/32/80406_2.png) [@Sander\_Marx](https://discuss.elastic.co/u/Sander_Marx)\
**Post date:** [April 28, 2021, 3:20pm UTC](https://discuss.elastic.co/t/how-to-search-over-all-fields-and-return-every-document-containing-that-search-in-elasticsearch/271533/1 "2021-04-28T15:20:28Z")

</div>

I have a problem regarding searching in elasticsearch.  
I have a index with multiple documents with several fields. I want to be able to search over all the fields running a query and want it to return all the documents that contains the value specified in the query. I Found that using `simple_query_string` worked well for this. However, it does not return consistent results. In my index I have documents with several fields that contain dates. For example:

```auto
"revisionDate" : "2008-01-01T00:00:00",
"projectSmirCreationDate" : "2008-07-01T00:00:00",
"changedDate" : "1971-01-01T00:00:00",
"dueDate" : "0001-01-01T00:00:00",

```

Those are just a few examples, however when I index for example:

```auto
GET new_document-20_v2/_search
{
  "size": 1000, 
  "query": {
    "simple_query_string" : {
        "query": "2008"
    }
  }
}

```

It only returns two documents, this is a problem because I have much more documents than just two that contains the value "2008" in their fields.

I also have problem searching file names.  
In my index there are fields that contain fileNames like this:

```auto
"fileName" : "testPDF.pdf",
"fileName" : "demo.pdf",
"fileName" : "demo.txt",

```

When i query:

```auto
GET new_document-20_v2/_search
{
  "size": 1000, 
  "query": {
    "simple_query_string" : {
        "query": "demo"
    }
  }
}

```

**I get no results**  
But if i query:

```auto
GET new_document-20_v2/_search
{
  "size": 1000, 
  "query": {
    "simple_query_string" : {
        "query": "demo.txt"
    }
  }
}

```

I get the proper result.

Is there any better way to search across all documents and fields than I did? I want it to return all the document matching the query and not just two or zero.  
Any help would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [April 29, 2021, 12:34am UTC](https://discuss.elastic.co/t/how-to-search-over-all-fields-and-return-every-document-containing-that-search-in-elasticsearch/271533/2 "2021-04-29T00:34:44Z")

</div>

What is the output from `_cat/indices/YOUR-INDEX?v`?

---

<div class="post-metadata">

**Author:** ![Sander\_Marx](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sander_marx/32/80406_2.png) [@Sander\_Marx](https://discuss.elastic.co/u/Sander_Marx)\
**Post date:** [April 30, 2021, 1:01am UTC](https://discuss.elastic.co/t/how-to-search-over-all-fields-and-return-every-document-containing-that-search-in-elasticsearch/271533/3 "2021-04-30T01:01:55Z")

</div>

I figured this out, ESCoder over on stackoverflow helped me out! Here is a link to soulution [kibana - How to search over all fields and return every document containing that search in elasticsearch? - Stack Overflow](https://stackoverflow.com/questions/67303015/how-to-search-over-all-fields-and-return-every-document-containing-that-search-i)

---

<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:** [May 28, 2021, 1:02am UTC](https://discuss.elastic.co/t/how-to-search-over-all-fields-and-return-every-document-containing-that-search-in-elasticsearch/271533/4 "2021-05-28T01:02:43Z")

</div>

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