# Elasticsearch python query does not display results

**URL:** <https://discuss.elastic.co/t/elasticsearch-python-query-does-not-display-results/236072>\
**Category:** Elasticsearch\
**Created:** [June 7, 2020, 6:14am UTC](https://discuss.elastic.co/t/elasticsearch-python-query-does-not-display-results/236072 "2020-06-07T06:14:57Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![vikramaddagulla](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vikramaddagulla/32/139858_2.png) [@vikramaddagulla](https://discuss.elastic.co/u/vikramaddagulla)\
**Post date:** [June 7, 2020, 6:14am UTC](https://discuss.elastic.co/t/elasticsearch-python-query-does-not-display-results/236072/1 "2020-06-07T06:14:58Z")

</div>

Hello

I am trying to query certain content using python query.

Below is my code :

```auto
from flask import Flask, render_template, request
from elasticsearch import Elasticsearch
import os
es = Elasticsearch( ['http://*******:9200'], http_auth=('elastic', '*****') )
search_term = "ikea"

res = es.search(index='dba_docs_folder', body={"query" : {"match": {"content": search_term}}, "highlight" : {"pre_tags" : ["<b>"] , "post_tags" : ["</b>"], "fields" : {"content":{}}}}, size=6000)

print(res)

```

I get the below output with the above query :

```auto
{'took': 0, 'timed_out': False, '_shards': {'total': 1, 'successful': 1, 'skipped': 0, 'failed': 0}, 'hits': {'total': {'value': 0, 'relation': 'eq'}, 'max_score': None, 'hits': []}}

```

I intend to get results matching search\_term. When I try to search the same using the kibana discover page, i get the desired results. But with the above query I get 0 hits.

Any suggestions on what am I doing wrong here ???

---

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [June 7, 2020, 6:29am UTC](https://discuss.elastic.co/t/elasticsearch-python-query-does-not-display-results/236072/2 "2020-06-07T06:29:58Z")

</div>

Hi @vikramaddagulla

Everything look fine, the only problem can be inside the query, double check that the query is really the same as the one you type in kibana.

As elastic don't return error, only an empty result it mean that you may hit another server that don't have the documents you search for (need to double check your configuration).

Can't really help more.

Not related with your problem but Just one question, do you really want 6000 results? if so, you can use scan helper it will help a lot or you can handle pagination.

[https://elasticsearch-py.readthedocs.io/en/master/helpers.html?highlight=scan#elasticsearch.helpers.scan](https://elasticsearch-py.readthedocs.io/en/master/helpers.html?highlight=scan#elasticsearch.helpers.scan)

---

<div class="post-metadata">

**Author:** ![vikramaddagulla](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vikramaddagulla/32/139858_2.png) [@vikramaddagulla](https://discuss.elastic.co/u/vikramaddagulla)\
**Post date:** [June 7, 2020, 6:36am UTC](https://discuss.elastic.co/t/elasticsearch-python-query-does-not-display-results/236072/3 "2020-06-07T06:36:36Z")

</div>

Running on Kibana meaning : I just tried searching the term on the discover page :

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/3/f/3ff27b8b0cc0474159a2193ccd9eedf599423e07.png)

As you can see in the above screen there are about 7 hits. I expect the python query also to return the same result set.

Is my understanding correct ??

Regarding the 6000 result set, I had not provided any result set initially and then read few blogs which spoke about providing result set to display the correct data set.

---

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [June 7, 2020, 6:42am UTC](https://discuss.elastic.co/t/elasticsearch-python-query-does-not-display-results/236072/4 "2020-06-07T06:42:35Z")

</div>

Problem with discovery page is it's search in all fields so you need to go to dev tools and try this:

```
GET dba_docs_folder/_search
{
    "query": {"match": {"content": "ikea"}}
}

```

if you don't have result please provide the mapping of your fields and one document example.

`GET dba_docs_folder/_mapping`

---

<div class="post-metadata">

**Author:** ![vikramaddagulla](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vikramaddagulla/32/139858_2.png) [@vikramaddagulla](https://discuss.elastic.co/u/vikramaddagulla)\
**Post date:** [June 7, 2020, 6:45am UTC](https://discuss.elastic.co/t/elasticsearch-python-query-does-not-display-results/236072/5 "2020-06-07T06:45:34Z")

</div>

Thanks for that. I tried searching the below on devtools

```auto
GET dba_docs_folder/_search
{
    "query": {"match": {"content": "ikea"}}
}

```

....and below is the response

```auto
{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 0,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : []
  }
}

```

---

<div class="post-metadata">

**Author:** ![vikramaddagulla](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vikramaddagulla/32/139858_2.png) [@vikramaddagulla](https://discuss.elastic.co/u/vikramaddagulla)\
**Post date:** [June 7, 2020, 6:49am UTC](https://discuss.elastic.co/t/elasticsearch-python-query-does-not-display-results/236072/6 "2020-06-07T06:49:36Z")

</div>

Below is the mapping in the JSON document for one of the hit via discover page.

There were some sensitive content and hence I had removed it and put \*\*\* in place of it.

```auto
{
  "_index": "dba_docs",
  "_type": "_doc",
  "_id": "e92453964e9c5269797bd2404db15",
  "_version": 1,
  "_score": null,
  "_source": {
    "content": ****************** ,
    "meta": {
      "date": "2020-05-19T17:08:11.000+00:00",
      "modifier": " *******",
      "created": "2006-09-16T04:00:00.000+00:00"
    },
    "file": {
      "extension": "xlsx",
      "content_type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
      "created": "2020-06-06T16:05:37.000+00:00",
      "last_modified": "2020-06-06T16:05:37.000+00:00",
      "last_accessed": "2020-06-06T16:05:37.000+00:00",
      "indexing_date": "2020-06-06T16:07:09.980+00:00",
      "filesize": 21832,
      "filename": "ContactDetails.xlsx",
      "url": "file:/// ********* ContactDetails.xlsx"
    },
    "path": {
      "root": "2ef0e2bd54555269df2c7fc26f2335",
      "virtual": "/ContactDetails.xlsx",
      "real": " ***** /ContactDetails.xlsx"
    }
  },
  "fields": {
    "file.last_modified": [
      "2020-06-06T16:05:37.000Z"
    ],
    "file.created": [
      "2020-06-06T16:05:37.000Z"
    ],
    "file.indexing_date": [
      "2020-06-06T16:07:09.980Z"
    ],
    "meta.created": [
      "2006-09-16T04:00:00.000Z"
    ],
    "file.last_accessed": [
      "2020-06-06T16:05:37.000Z"
    ],
    "meta.date": [
      "2020-05-19T17:08:11.000Z"
    ],
    "file.filename": [
      "ContactDetails.xlsx"
    ]
  },
  "highlight": {
    "content": [
      " ***********************"
    ]
  },
  "sort": [
    1591459629980
  ]
}

```

---

<div class="post-metadata">

**Author:** ![vikramaddagulla](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vikramaddagulla/32/139858_2.png) [@vikramaddagulla](https://discuss.elastic.co/u/vikramaddagulla)\
**Post date:** [June 7, 2020, 6:51am UTC](https://discuss.elastic.co/t/elasticsearch-python-query-does-not-display-results/236072/7 "2020-06-07T06:51:17Z")

</div>

Aaah...My bad...

I think I was searching in the wrong index..

I had to search under dba\_docs  
Instead...  
I was searching under dba\_docs\_folder

---

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [June 7, 2020, 6:56am UTC](https://discuss.elastic.co/t/elasticsearch-python-query-does-not-display-results/236072/8 "2020-06-07T06:56:16Z")

</div>

Just for information the mapping is not the result you provided, what you provided is a document.

something that you can get with this query:

`GET dba_docs/_doc/e92453964e9c5269797bd2404db15`

the mapping is the result of this query:

`GET dba_docs_folder/_mapping`

It give information on how your data are stored.  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html)

Good that your problem is solved! 😀

---

<div class="post-metadata">

**Author:** ![vikramaddagulla](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vikramaddagulla/32/139858_2.png) [@vikramaddagulla](https://discuss.elastic.co/u/vikramaddagulla)\
**Post date:** [June 7, 2020, 7:07am UTC](https://discuss.elastic.co/t/elasticsearch-python-query-does-not-display-results/236072/9 "2020-06-07T07:07:18Z")

</div>

Thank you....Noted....I am still new to elastic and playing around...

The problem is now fixed and I am getting the required output.

---

<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:** [July 5, 2020, 7:07am UTC](https://discuss.elastic.co/t/elasticsearch-python-query-does-not-display-results/236072/10 "2020-07-05T07:07:24Z")

</div>

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