# How to search Multiple dense vector fields, including nested filelds

**URL:** <https://discuss.elastic.co/t/how-to-search-multiple-dense-vector-fields-including-nested-filelds/326119>\
**Category:** Elasticsearch\
**Tags:** vector-search\
**Created:** [February 22, 2023, 5:04am UTC](https://discuss.elastic.co/t/how-to-search-multiple-dense-vector-fields-including-nested-filelds/326119 "2023-02-22T05:04:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shijithp007](https://avatars.discourse-cdn.com/v4/letter/s/3bc359/32.png) [@shijithp007](https://discuss.elastic.co/u/shijithp007)\
**Post date:** [February 22, 2023, 5:04am UTC](https://discuss.elastic.co/t/how-to-search-multiple-dense-vector-fields-including-nested-filelds/326119/1 "2023-02-22T05:04:10Z")

</div>

I am working on semantic search, where i try to save processed results of scraped website data. Website has title, summary, sub\_section\_headings and sub\_section\_data. i am storing title & summary as `dense vectors` and sub\_section\_headings & sub\_section\_data as `nested dense vectors` [sub\_section\_data **has more vectors** than sub\_section\_headings]. my mapping is as below [using Elasticsearch version **7.10**]

```auto
"mappings": {
            "dynamic": "strict",
            "properties": {
                "title_vector": {"type": "dense_vector","dims": 768},
                "summary_vector": {"type": "dense_vector","dims": 768},
                "sub_section_headings_vectors": {
                    "type": "nested",
                    "properties": {"vector": {"type": "dense_vector","dims": 768}}
                },
                "sub_section_data_vectors": {
                    "type": "nested",
                    "properties": {"vector": {"type": "dense_vector", "dims": 768}}
                }
}}

```

Please suggest a method to search all these fields at a time, or at least multiple nested vectors.  
my current query is as below

```auto
# for nested fields, sub_section_headings & sub_section_data 
'query': {
                'nested': {'path': 'sub_section_headings',
                           'score_mode': 'max',
                           'query': {'function_score': {'script_score': {'script': {
                               'source': ''(1.0+cosineSimilarity(params.query_vector, params.field))'',
                               'params': {'field': 'sub_section_headings.vector', 'query_vector': [0.32, 0.89, ...]}}}}}
                           }
            }

# for title & summary
  'query': {
      'script_score': {
          'query': {'exists': {'field': 'title_vector'}},
          'script': {
              'source': '(1.0+cosineSimilarity(params.query_vector, params.field))',
              'params': {'field': 'title_vector', 'query_vector': [0.32, 0.89, ...]}
          }
      }
  }

```

Currently i am doing 4 searches, one each for all the fields. , How can i optimise? Please help

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [February 22, 2023, 11:51am UTC](https://discuss.elastic.co/t/how-to-search-multiple-dense-vector-fields-including-nested-filelds/326119/2 "2023-02-22T11:51:52Z")

</div>

Hi @shijithp007

You tried put the four clausules inside "should"?

---

<div class="post-metadata">

**Author:** ![BenTrent](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bentrent/32/33915_2.png) [@BenTrent](https://discuss.elastic.co/u/BenTrent)\
**Post date:** [February 22, 2023, 12:52pm UTC](https://discuss.elastic.co/t/how-to-search-multiple-dense-vector-fields-including-nested-filelds/326119/3 "2023-02-22T12:52:46Z")

</div>

@RabBit_BR is correct, you need to use a [Boolean query | Elasticsearch Guide [8.6] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html)

You can then determine which clauses are "AND" clauses (must & filter), or "OR" clauses (should).

---

<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:** [February 22, 2023, 12:58pm UTC](https://discuss.elastic.co/t/how-to-search-multiple-dense-vector-fields-including-nested-filelds/326119/4 "2023-02-22T12:58:04Z")

</div>

I would also recommend you upgrade to the latest version as 7.10 is EOL and a lot of improvements in this area has been made since that release.

---

<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:** [March 22, 2023, 12:59pm UTC](https://discuss.elastic.co/t/how-to-search-multiple-dense-vector-fields-including-nested-filelds/326119/5 "2023-03-22T12:59:01Z")

</div>

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