# More\_Like\_This Query returns no results via python requests, but shows results in Opensearch Dashboards Dev Tools

**URL:** <https://forum.opensearch.org/t/more-like-this-query-returns-no-results-via-python-requests-but-shows-results-in-opensearch-dashboards-dev-tools/21989>\
**Category:** OpenSearch\
**Tags:** troubleshoot\
**Created:** [October 17, 2024, 10:18am UTC](https://forum.opensearch.org/t/more-like-this-query-returns-no-results-via-python-requests-but-shows-results-in-opensearch-dashboards-dev-tools/21989 "2024-10-17T10:18:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pam](https://avatars.discourse-cdn.com/v4/letter/p/f6c823/32.png) [@pam](https://forum.opensearch.org/u/pam)\
**Post date:** [October 17, 2024, 10:18am UTC](https://forum.opensearch.org/t/more-like-this-query-returns-no-results-via-python-requests-but-shows-results-in-opensearch-dashboards-dev-tools/21989/1 "2024-10-17T10:18:53Z")

</div>

Hello everybody,

we are having problems with the More\_Like\_This query type.

**Versions** (relevant - OpenSearch/Dashboard/Server OS/Browser):  
AWS Managed Cluster Opensearch Version 2.11 - Software version OpenSearch\_2\_11\_R20240502-P3

**Describe the issue** :  
To query data via a More\_Like\_This query we have an AWS Lambda function that accesses the cluster and performs the query. This lambda function runs on python 3.11 and sends the query via python requests with authentication information from requests\_aws4auth package to an index alias. Unfortunately this query returns no hits (and no error/ timeout). However when i perform the same query via Opensearch Dashboards Dev Tools i get the expected hits.  
Does anybody else experienced this behavior or knows a solution, why the lambda does not get the expected results, but Dashboards Dev Tools?

**Configuration** :

The following query shows the described behavior:

```json
{
        "from": 0,
        "size": 10,
        "query": {
            "more_like_this": {
                "fields": [
                    "content",
                    "ents.all"
                ],
                "like": [
                    {
                        "_id": "ebc7df84-33d1-430a-a9d7-b7f6e9424987"
                    }
                ],
                "max_query_terms": 25,
                "min_term_freq": 1,
                "min_doc_freq": 1
            }
        },
        "fields": [
            "id"
        ],
        "_source": false
    }

```

Our minimal document schema for this query is:

```json
{
"id": "another id of our document",
"content": "the text content of our document",
"ents": {
    "all": ["ent1", "ent2"]
}

```

Relevant python script part:

```python
creds = boto3.Session().get_credentials()
auth = requests_aws4auth.AWS4Auth(creds.access_key,
                                  creds.secret_key,
                                  region,
                                  'es',
                                  session_token=creds.token)
session = requests.Session()
session.auth = auth
url = f"{domainUrl}/myIndexAlias/_search"

response = session.get(url=self.url, json=query, timeout=20).json()

```

Python script response:

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

```

Opensearch Dashboards Dev Tools:

GET myIndexAlias/\_search

```json
{
        "query": {
            "more_like_this": {
                "fields": [
                    "content",
                    "ents.all"
                ],
                "like": [
                    {
                        "_id": "ebc7df84-33d1-430a-a9d7-b7f6e9424987"
                    }
                ],
                "max_query_terms": 25,
                "min_term_freq": 1,
                "min_doc_freq": 1
            }
        },
        "fields": [
            "id"
        ],
        "_source": false
    }

```

Response (shortened):

```json
{
  "took": 483,
  "timed_out": false,
  "_shards": {
    "total": 12,
    "successful": 12,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 154,
      "relation": "eq"
    },
    "max_score": 119.72375,
    "hits": [
      {
        "_index": "myIndex1",
        "_id": "a4475c30-ba64-460d-ae22-608ece79dc2a",
        "_score": 119.72375,
        "fields": {
          "id": [
            "a4475c30-ba64-460d-ae22-608ece79dc2a"
          ]
        }
      },
      {
        "_index": "myIndex1",
        "_id": "93113ea3-5a5d-4260-8f90-fc4f8b0ec98d",
        "_score": 28.89265,
        "fields": {
          "id": [
            "93113ea3-5a5d-4260-8f90-fc4f8b0ec98d"
          ]
        }
      },
      {
        "_index": "myIndex2",

```

**Relevant Logs or Screenshots** :

- we experienced the same behavior with AWS managed cluster Opensearch version 2.9
- we investigated permissions, but did not find anything, that could be the cause of this behavior

Thank you already for any tips & leads!
