Skip to content

knn query on semantic_text field with semantic_text filter fails #138410

@dimitris-athanasiou

Description

@dimitris-athanasiou

Elasticsearch Version

9.2

Installed Plugins

No response

Java Version

bundled

OS Version

Darwin

Problem Description

A knn query on a semantic_text field fails when it contains filters that are other queries on semantic_text fields (e.g. knn, sparse_vector, match).

Steps to Reproduce

PUT example
{
    "settings": {
        "number_of_shards": 1,
        "number_of_replicas": 0
    },
    "mappings": {
        "properties": {
            "semantic_1": {
                "type": "semantic_text",
                "inference_id": ".multilingual-e5-small-elasticsearch"
            },
            "semantic_2": {
                "type": "semantic_text",
                "inference_id": ".multilingual-e5-small-elasticsearch"
            }
        }
    }
}

POST example/_doc
{
    "semantic_1" : "something",
    "semantic_2": "else"
}

POST example/_search
{

    "query": {
        "knn": {
            "field": "semantic_1",
            "k": 10,
            "num_candidates": 10,
            "query_vector_builder": {
                "text_embedding": {
                    "model_text":"something"
                }
            },
            "filter": {
                "match": {
                    "semantic_2": {
                        "query": "else"
                    }
                }
            }
        }
    }
}

POST example/_search
{

    "query": {
        "knn": {
            "field": "semantic_1",
            "k": 10,
            "num_candidates": 10,
            "query_vector_builder": {
                "text_embedding": {
                    "model_text":"something"
                }
            },
            "filter": {
                "knn": {
                    "field": "semantic_2",
                    "k": 10,
                    "num_candidates": 10,
                    "query_vector_builder": {
                        "text_embedding": {
                            "model_text":"else"
                        }
                    }
                }
            }
        }
    }
}

The first search fails with:

{
  "error": {
    "root_cause": [
      {
        "type": "query_shard_exception",
        "reason": "failed to create query: Field [semantic_2] of type [semantic_text] does not support match queries",
        "index_uuid": "L3c8k2aUSs-Op5fBJ4ve7Q",
        "index": "example"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "example",
        "node": "-NqAZhF6RRyaxBJIjRIdiA",
        "reason": {
          "type": "query_shard_exception",
          "reason": "failed to create query: Field [semantic_2] of type [semantic_text] does not support match queries",
          "index_uuid": "L3c8k2aUSs-Op5fBJ4ve7Q",
          "index": "example",
          "caused_by": {
            "type": "illegal_argument_exception",
            "reason": "Field [semantic_2] of type [semantic_text] does not support match queries"
          }
        }
      }
    ]
  },
  "status": 400
}

The second fails with:

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_state_exception",
        "reason": "async actions are left after rewrite"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "example",
        "node": "-NqAZhF6RRyaxBJIjRIdiA",
        "reason": {
          "type": "illegal_state_exception",
          "reason": "async actions are left after rewrite"
        }
      }
    ],
    "caused_by": {
      "type": "illegal_state_exception",
      "reason": "async actions are left after rewrite",
      "caused_by": {
        "type": "illegal_state_exception",
        "reason": "async actions are left after rewrite"
      }
    }
  },
  "status": 500
}

Metadata

Metadata

Labels

:SearchOrg/RelevanceLabel for the Search (solution/org) Relevance team>bugTeam:Search - RelevanceThe Search organization Search Relevance team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions