# ELSER hybrid search. Error: '\[sub\_searches\] query malformed, no start\_object after query name')

**URL:** <https://discuss.elastic.co/t/elser-hybrid-search-error-sub-searches-query-malformed-no-start-object-after-query-name/351802>\
**Category:** Elastic Search\
**Tags:** elastic-workplace-search\
**Created:** [January 25, 2024, 1:48pm UTC](https://discuss.elastic.co/t/elser-hybrid-search-error-sub-searches-query-malformed-no-start-object-after-query-name/351802 "2024-01-25T13:48:31Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![SanthoshKMurugadass](https://avatars.discourse-cdn.com/v4/letter/s/b9e5f3/32.png) [@SanthoshKMurugadass](https://discuss.elastic.co/u/SanthoshKMurugadass)\
**Post date:** [January 25, 2024, 1:48pm UTC](https://discuss.elastic.co/t/elser-hybrid-search-error-sub-searches-query-malformed-no-start-object-after-query-name/351802/1 "2024-01-25T13:48:31Z")

</div>

I am trying a develop a hybrid search query by combing ELSER Semantic and Full Text searches using Python client. Below is my sample code. I am getting a error

**'[sub\_searches] query malformed, no start\_object after query name')**

Looks i am missing some think in Syntax. Any help is welcome.

```auto
query_text ="CMOS"
index_Name_emb="sales_test"
emdeddingmodel=".elser_model_2"

resp = client.search(index=index_Name_emb,
                query={
                        "sub_searches":[
                        {
                            "query":{
                            "multi_match" : {
                            "query":query_text,
                            "fields": ["content","sourceTitle"], # Searches both 'content' and "title" fileds
                                            }
                                }
                        },
                        {
                            "query":{
                                "text_expansion":{
                                "content_embedding":{
                                    "model_id":emdeddingmodel,
                                    "model_text":query_text,
                                                    }
                                                }
                                    }
                        }
                                        ],
                        "rank":{
                            "rrf": {
                                "window_size": 50,
                                "rank_constant": 20
                                    }
                                }
                    },
                size=5,
                from_=0,
                source=True
				)
print(resp)

```

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [January 25, 2024, 2:09pm UTC](https://discuss.elastic.co/t/elser-hybrid-search-error-sub-searches-query-malformed-no-start-object-after-query-name/351802/2 "2024-01-25T14:09:08Z")

</div>

Which version of Elasticsearch are you using?

---

<div class="post-metadata">

**Author:** ![SanthoshKMurugadass](https://avatars.discourse-cdn.com/v4/letter/s/b9e5f3/32.png) [@SanthoshKMurugadass](https://discuss.elastic.co/u/SanthoshKMurugadass)\
**Post date:** [January 25, 2024, 2:20pm UTC](https://discuss.elastic.co/t/elser-hybrid-search-error-sub-searches-query-malformed-no-start-object-after-query-name/351802/3 "2024-01-25T14:20:53Z")

</div>

I am using '8.11.1'

---

<div class="post-metadata">

**Author:** ![SanthoshKMurugadass](https://avatars.discourse-cdn.com/v4/letter/s/b9e5f3/32.png) [@SanthoshKMurugadass](https://discuss.elastic.co/u/SanthoshKMurugadass)\
**Post date:** [January 25, 2024, 2:43pm UTC](https://discuss.elastic.co/t/elser-hybrid-search-error-sub-searches-query-malformed-no-start-object-after-query-name/351802/4 "2024-01-25T14:43:46Z")

</div>

In fact, both full text search and semantic search queries are working as expected independently. I face error when I combine them using sub\_searches.

---

<div class="post-metadata">

**Author:** ![Kathleen\_DeRusso](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kathleen_derusso/32/132039_2.png) [@Kathleen\_DeRusso](https://discuss.elastic.co/u/Kathleen_DeRusso)\
**Post date:** [January 25, 2024, 2:50pm UTC](https://discuss.elastic.co/t/elser-hybrid-search-error-sub-searches-query-malformed-no-start-object-after-query-name/351802/5 "2024-01-25T14:50:51Z")

</div>

Are you sending in `sub_searches` under the query parameter? It should be at the top level, as in [this](https://www.elastic.co/guide/en/elasticsearch/reference/current/rrf.html#rrf-using-sub-searches) example.

---

<div class="post-metadata">

**Author:** ![SanthoshKMurugadass](https://avatars.discourse-cdn.com/v4/letter/s/b9e5f3/32.png) [@SanthoshKMurugadass](https://discuss.elastic.co/u/SanthoshKMurugadass)\
**Post date:** [January 29, 2024, 7:40am UTC](https://discuss.elastic.co/t/elser-hybrid-search-error-sub-searches-query-malformed-no-start-object-after-query-name/351802/6 "2024-01-29T07:40:42Z")

</div>

@Kathleen_DeRusso Thanks for looking into it.

When i keep sub\_searches under top level in my code, i am getting error that Elasticsearch.search() got an unexpected keyword argument 'sub\_searches'.

The link that you pointed has CURL code, that works inside Dev Tool Console. But when i am writing python i am missing something minor thing. I searhed on Elastic Websites and open internet for a sample python code, but no luck.  
A wokring sample python code for 'sub\_searches' would be of great help.

```auto
query_text ="CMOS"
index_Name_emb="sales_test"
emdeddingmodel=".elser_model_2"

# Perform the search
resp= client.search(index=index_Name_emb,
                    size=5,
                    from_=0,
                    source=True,
                    sub_searches=[
                        {
                            "query":{
                            "multi_match" : {
                                "query":"CMOS",
                                "fields": ["content","sourceTitle"]
                                }
                                }
                            },
                            {
                                "query":{
                                "text_expansion":{
                                    "content_embedding":{
                                    "model_id":".elser_model_2",
                                    "model_text":"CMOS"
                                    }
                                }
                                }
                            }
                        ],
                        rank={
                            "rrf": {
                                "window_size": 50,
                                "rank_constant": 20
                                    }
                                }

        )
resp

```

---

<div class="post-metadata">

**Author:** ![joemcelroy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joemcelroy/32/103757_2.png) [@joemcelroy](https://discuss.elastic.co/u/joemcelroy)\
**Post date:** [January 29, 2024, 8:44am UTC](https://discuss.elastic.co/t/elser-hybrid-search-error-sub-searches-query-malformed-no-start-object-after-query-name/351802/7 "2024-01-29T08:44:49Z")

</div>

hi there,

`sub_searches` is still in technical preview and not currently supported by the python lang client. The error you see is being thrown by the client, due to unsupported syntax.

See this doc on how to use sub\_searches in python via request. [Hybrid Search — Elastic Search Labs](https://www.elastic.co/search-labs/tutorials/search-tutorial/semantic-search/hybrid-search#introduction-to-sub-searches)

Joe

---

<div class="post-metadata">

**Author:** ![SanthoshKMurugadass](https://avatars.discourse-cdn.com/v4/letter/s/b9e5f3/32.png) [@SanthoshKMurugadass](https://discuss.elastic.co/u/SanthoshKMurugadass)\
**Post date:** [January 29, 2024, 9:06am UTC](https://discuss.elastic.co/t/elser-hybrid-search-error-sub-searches-query-malformed-no-start-object-after-query-name/351802/8 "2024-01-29T09:06:23Z")

</div>

Hi @joemcelroy Thanks for response.

I could get the results when i execute below code inside Kibana Dev Tool console. All good.

```auto
GET sales_content_appbriefs_test_dele/_search
{
  "sub_searches":[
    {
      "query":{
        "multi_match" : {
          "query":"CMOS",
          "fields": ["content","sourceTitle_lvl1"]
        }
      }
    },
    {
      "query":{
        "text_expansion":{
          "content_embedding":{
            "model_id":".elser_model_2",
            "model_text":"CMOS"
          }
        }
      }
    }
    ],
    "rank":{
      "rrf": {
        "window_size": 50,
        "rank_constant": 20
      }
    }
}

```

I formatted same code in Python Lang client.

ConnectionError: Connection error caused by: ConnectionError(Connection error caused by: HostChangedError(HTTPSConnectionPool(host='10.32.25.065', port=9200): Tried to open a foreign host with url: sales\_content/\_search))

```auto
rep=client.perform_request(
            method='GET',
            path=f'sales_content/_search',
            headers={'Content-Type': 'application/json',
                     'Accept': 'application/json'},
            body=json.dumps({
                    'sub_searches':[
                        {
                            "query":{
                            "multi_match" : {
                                "query":"CMOS",
                                "fields": ["content","sourceTitle_lvl1"]
                                }
                                }
                            },
                            {
                                "query":{
                                "text_expansion":{
                                    "content_embedding":{
                                    "model_id":".elser_model_2",
                                    "model_text":"CMOS"
                                    }
                                }
                                }
                            }
                        ],
                        "rank":{
                            "rrf": {
                                "window_size": 50,
                                "rank_constant": 20
                                    }
                                }
                    }),
)
resp

```

Also there is a statement in the tutorial link that says :  
**With this version** , the `sub_searches` argument can be used to send multiple search queries as follows:

What is intented to convey by **With this version**? What version ? which library ?

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/5/753963a2c2d7fc340f6dc3d2dd73add29041e8a7.png)

---

<div class="post-metadata">

**Author:** ![joemcelroy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joemcelroy/32/103757_2.png) [@joemcelroy](https://discuss.elastic.co/u/joemcelroy)\
**Post date:** [January 29, 2024, 9:43am UTC](https://discuss.elastic.co/t/elser-hybrid-search-error-sub-searches-query-malformed-no-start-object-after-query-name/351802/9 "2024-01-29T09:43:59Z")

</div>

Hey,

Might be down to your indexName is incorrect. In your example, you are performing a search to ` sales_content_appbriefs_test_dele` and the python code is `sales_content`

Python Lang client version should match the Elasticsearch version.

The version is talking specifically that the version of how the query is called (in previous examples we are calling using the `search` method, now been changed with `perform_request`. Its not talking about the version of the client.

Joe

---

<div class="post-metadata">

**Author:** ![SanthoshKMurugadass](https://avatars.discourse-cdn.com/v4/letter/s/b9e5f3/32.png) [@SanthoshKMurugadass](https://discuss.elastic.co/u/SanthoshKMurugadass)\
**Post date:** [January 29, 2024, 10:15am UTC](https://discuss.elastic.co/t/elser-hybrid-search-error-sub-searches-query-malformed-no-start-object-after-query-name/351802/10 "2024-01-29T10:15:32Z")

</div>

Thanks.  
Index name i am using is correct. I am trying with different names. Two different names are seen in earlier code and previous code is just due to the face that they come from 2 different trails.

May i know what exactly the Path ? Is this path=f'sales\_content/\_search', is correct if want to search index name sales\_content ?

---

<div class="post-metadata">

**Author:** ![SanthoshKMurugadass](https://avatars.discourse-cdn.com/v4/letter/s/b9e5f3/32.png) [@SanthoshKMurugadass](https://discuss.elastic.co/u/SanthoshKMurugadass)\
**Post date:** [January 29, 2024, 11:44am UTC](https://discuss.elastic.co/t/elser-hybrid-search-error-sub-searches-query-malformed-no-start-object-after-query-name/351802/11 "2024-01-29T11:44:55Z")

</div>

> [@SanthoshKMurugadass](#):
>
> `path=f'sales_content/_search',`

I got where the problem was; There should have been a back slosh(/) at the begning of the path as below.

```auto
path=f' **/** sales_content/_search',

```

Thanks for all your suggestions.

Any idea on time line by when sub\_searches moved from technical review to production release ?

---

<div class="post-metadata">

**Author:** ![joemcelroy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joemcelroy/32/103757_2.png) [@joemcelroy](https://discuss.elastic.co/u/joemcelroy)\
**Post date:** [January 29, 2024, 1:00pm UTC](https://discuss.elastic.co/t/elser-hybrid-search-error-sub-searches-query-malformed-no-start-object-after-query-name/351802/12 "2024-01-29T13:00:57Z")

</div>

We're still discussing internally. The syntax is currently being discussed and finalised in the next couple of releases I hope.

Joe

---

<div class="post-metadata">

**Author:** ![SanthoshKMurugadass](https://avatars.discourse-cdn.com/v4/letter/s/b9e5f3/32.png) [@SanthoshKMurugadass](https://discuss.elastic.co/u/SanthoshKMurugadass)\
**Post date:** [January 29, 2024, 1:44pm UTC](https://discuss.elastic.co/t/elser-hybrid-search-error-sub-searches-query-malformed-no-start-object-after-query-name/351802/13 "2024-01-29T13:44:06Z")

</div>

Thanks Joe. That’s a useful info.

---

<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 26, 2024, 1:44pm UTC](https://discuss.elastic.co/t/elser-hybrid-search-error-sub-searches-query-malformed-no-start-object-after-query-name/351802/14 "2024-02-26T13:44:57Z")

</div>

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