Sparse_vector query is not working

following this doc i have created index with the mapping shown in the docs but when i am querying through the data, i am getting this error

{
  "error": {
    "root_cause": [
      {
        "type": "parsing_exception",
        "reason": "unknown query [sparse_vector]",
        "line": 3,
        "col": 22
      }
    ],
    "type": "parsing_exception",
    "reason": "unknown query [sparse_vector]",
    "line": 3,
    "col": 22,
    "caused_by": {
      "type": "named_object_not_found_exception",
      "reason": "[3:22] unknown field [sparse_vector]"
    }
  },
  "status": 400
}

I am using elser model here

What version of Elasticsearch are you using?

"number": "8.14.3",
"build_flavor": "default",
"build_type": "docker",
"build_date": "2024-07-07T22:04:49.882652950Z",
"build_snapshot": false,
"lucene_version": "9.10.0",
"minimum_wire_compatibility_version": "7.17.0",
"minimum_index_compatibility_version": "7.0.0"

The guide you linked to is for Elasticsearch 8.15. Always make sure you are looking at the documentation for the version you are using, especially when working in an area that moves as quickly as vector serach. I would recommend you upgrade to the latest version of Elasticsearch (or consult the documentation for the correct version - there has been changes to the page you linked to betwen these versions).

Thanks for your advise!

could you assist me in setting up for search query.

i have setup my ingest pipeline like this where combined content is joining all fields that i have in my document.

{
      "inference": {
        "model_id": ".elser_model_2",
        "input_output": [
          {
            "input_field": "combined_content",
            "output_field": "content_embedding"
          }
        ]
      }
    }

my search query looks like this

{
          size: 1000,
          query: {
            bool: {
              should: [
                {
                  text_expansion: {
                    content_embedding: {
                      model_text: model_text,
                      model_id: elasticModelId,
                      boost: 4,
                    },
                  },
                },
              ],
              minimum_should_match: 1,
            },
          },
          _source: {
            excludes: [
              "content_embedding",
              "combined_content",
            ],
          },
          min_score: parseFloat(min_score),
        }

but i want to prioritize certain fields so how can i achieve that?

I'd also recommend upgrading to 8.15.0 - which is the version where the sparse_vector query launched.

If you want to prioritize certain fields, you'll want to add additional boost query clauses to your boolean query.

yes, i have upgraded es version to 8.15.0.

could you help me building the query as i have fields like name, address and description and i want to prioritize search result for name and adress and description should have very less priorities.

i know how we can set priorities for a normal search but how to do it when using an elser model for semantic search.

The easiest way to do this is with RRF. We have some examples in our documentation about how you can do hybrid search that combines standard text search with semantic search and reranking them with RRF. This should get you started.

Alternately you can use linear boosting in each boolean clause in your query.

Thanks for you assistance! thats really helpful

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