Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

text_expansion queries return results for specified text fields #116046

Open
kderusso opened this issue Oct 31, 2024 · 3 comments
Open

text_expansion queries return results for specified text fields #116046

kderusso opened this issue Oct 31, 2024 · 3 comments
Labels
>bug :ml Machine learning :SearchOrg/Relevance Label for the Search (solution/org) Relevance team

Comments

@kderusso
Copy link
Member

Elasticsearch Version

8.15.3

Installed Plugins

No response

Java Version

bundled

OS Version

Cloud

Problem Description

Running a text_expansion query against a field that is not sparse_vector or rank_features returns results, when it should not. This only happens on text_expansion and not sparse_vector queries.

See the following script:

PUT _inference/sparse_embedding/my-elser-model
{
  "service": "elser",
  "service_settings": {
    "num_allocations": 1,
    "num_threads": 1
  }
}

GET _inference/sparse_embedding/my-elser-model

PUT my-test-index
{
  "mappings": {
    "properties": {
      "my_text_field": {
        "type": "text"
      },
      "my_vector_field": {
        "type": "sparse_vector"
      }
    }
  }
}

POST /_ml/trained_models/.elser_model_2_linux-x86_64/_infer
{
  "docs":[{"text_field": "Happy Halloween"}]
}


PUT my-test-index/_doc/1
{
  "my_text_field": "Happy Halloween",
  "my_vector_field": {
    "halloween": 2.7842348,
    "happy": 2.5733197,
    "horror": 0.8652177,
    "holiday": 0.85693324,
    "scare": 0.7672729,
    "christmas": 0.6851733,
    "festival": 0.6763591,
    "fear": 0.6434108,
    "zombie": 0.6021877,
    "spirit": 0.5376576,
    "october": 0.46978226,
    "birthday": 0.44018516,
    "scary": 0.36408967,
    "haunted": 0.3599118,
    "funeral": 0.3351968,
    "monster": 0.31106675,
    "joke": 0.2926158,
    "boo": 0.2861689,
    "costume": 0.27760586,
    "grin": 0.24734442,
    "batman": 0.22178747,
    "ritual": 0.22164688,
    "skull": 0.19528879,
    "sympathy": 0.1890748,
    "pumpkin": 0.18315344,
    "fun": 0.1805031,
    "humor": 0.17760311,
    "death": 0.15597177,
    "eve": 0.11133687,
    "!": 0.09539104,
    "cartoon": 0.09466279,
    "surprise": 0.06276361,
    "movie": 0.058513653,
    "grave": 0.058063928,
    "halle": 0.039445546,
    "cursed": 0.037154045,
    "dance": 0.014831517
  }
}


// Returns a result as expected
POST my-test-index/_search
{
  "query": {
    "text_expansion": {
      "my_vector_field": {
        "model_id": ".elser_model_2_linux-x86_64",
        "model_text": "happy"
      }
    }
  }
}

// Should not return results but does
GET my-test-index/_search
{
  "query": {
    "text_expansion": {
      "my_text_field": {
        "model_id": ".elser_model_2_linux-x86_64",
        "model_text": "happy"
      }
    }
  }
}

// Returns a result 
POST my-test-index/_search
{
  "query": {
    "sparse_vector": {
      "field": "my_vector_field",
      "inference_id": "my-elser-model",
      "query": "happy"
    }
  }
}

// Errors on mapping type (expected behavior)
POST my-test-index/_search
{
  "query": {
    "sparse_vector": {
      "field": "my_text_field",
      "inference_id": "my-elser-model",
      "query": "happy"
    }
  }
}

Steps to Reproduce

See attached script.

Logs (if relevant)

No response

@kderusso kderusso added :ml Machine learning :SearchOrg/Relevance Label for the Search (solution/org) Relevance team >bug labels Oct 31, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/ml-core (Team:ML)

@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/search-eng (Team:SearchOrg)

@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/search-relevance (Team:Search - Relevance)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :ml Machine learning :SearchOrg/Relevance Label for the Search (solution/org) Relevance team
Projects
None yet
Development

No branches or pull requests

2 participants