opensearch-project / opensearch-js

Node.js Client for OpenSearch
https://opensearch.org/docs/latest/clients/javascript/
Apache License 2.0
179 stars 118 forks source link

[BUG] Not able to search for texts with space and dash in between. #692

Closed aniruddha-mahamuni-bh closed 5 months ago

aniruddha-mahamuni-bh commented 5 months ago

What is the bug?

I am using Javascript client https://opensearch.org/docs/latest/clients/javascript/index/ to fetch data from opensearch. I am using the below query to fetch data

{
  "track_total_hits": true,
  "from": 0,
  "size": 100,
  "query": {
    "bool": {
      "should": [
        {
          "wildcard": {
            "name": "*test *"
          }
        },
        {
          "wildcard": {
            "description": "*test *"
          }
        }
      ]
    }
  },
  "_source": ["name", "description"], 
  "track_scores": true
}

In our data set we have name and description as "test data" for few records. So, in the query if we give input as test with space (test ) it is not returning the data set with name as "test data" or "test-data". The same scenario if for dash in between the text In our data set we have name and description as "test-data" for few records. So, in the query if we give input as test with a hyphen/dash (test-) it is not returning the data set with name/description as "test-data".

Check below image for response image

How can one reproduce the bug?

To reproduce the bug you can use the above query for testing the spaces issue. For testing the hyphen/dash issue you can refer the below query

{
  "track_total_hits": true,
  "from": 0,
  "size": 100,
  "query": {
    "bool": {
      "should": [
        {
          "wildcard": {
            "name": "*test-*"
          }
        },
        {
          "wildcard": {
            "description": "*test-*"
          }
        }
      ]
    }
  },
  "_source": ["name", "description"], 
  "track_scores": true
}

What is the expected behavior?

It should return data for text with spaces and hyphen/dash.

What is your host/environment?

Operating system - Linux, opensearch version - https://opensearch.org/docs/2.11/about/.

Do you have any screenshots?

If applicable, add screenshots to help explain your problem.

Do you have any additional context?

Add any other context about the problem.

dblock commented 5 months ago

Is the query the problem or the client? Meaning can this be reproduced with curl?

aniruddha-mahamuni-bh commented 5 months ago

Thanks @dblock Yes it can be reproduced using curl also. This is now fixed. We fixed this by adding params in index mappings We have added in the properties section of name, description.

"analyzer": "keyword_lowercase",
"fielddata": true