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

Unable to correctly query data using 'query_string' #109434

Closed
LiJie20190102 opened this issue Jun 6, 2024 · 2 comments
Closed

Unable to correctly query data using 'query_string' #109434

LiJie20190102 opened this issue Jun 6, 2024 · 2 comments
Labels
:Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team

Comments

@LiJie20190102
Copy link

LiJie20190102 commented Jun 6, 2024

Elasticsearch Version

7.17.21

Installed Plugins

No response

Java Version

21.0.2

OS Version

3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

Problem Description

I use "search profile" to obtain the analysis results. I obtained all the "MultiTermQueryConstantScoreWrappers", and I used each "MultiTermQueryConstantScoreWrapper" separately to obtain the data. However, when I used all the "MultiTermQueryConstantScoreWrappers", I could not obtain the correct results

Steps to Reproduce

1. prepare data

`PUT user_aaa
{
"mappings": {
"properties": {
"address": {
"type": "text",
"index": false
},
"age": {
"type": "long"
},
"name": {
"type": "text"
}
}
}
}

PUT user_aaa/_doc/1
{
"name":"04V5:J20240506104423001!1!130322198402082311"
}

PUT user_aaa/_doc/2
{
"name":"04V5!J20240506104423001!1!130322198402082311"
}

`

2. search script

GET user_aaa/_search? { "query": { "query_string": { "query": "04V5*!J20240506104423001*!1*!130322198402082311*", "fields": ["name"] } } }

at this time, data cannot be queried

3. kibana 'Search Profile'

image

4. When "query" is "04v5 *", "1 *", "j2024050610423001 *", "130322198402082311 *", data can be searched, and all are MultiTermQueryConstantScoreWrappers. However, when "query" is "04V5 *! J2024050610423001 *! 1 *! 130322198402082311 *", data cannot be searched

image

image

Logs (if relevant)

No response

@LiJie20190102 LiJie20190102 added >bug needs:triage Requires assignment of a team area label labels Jun 6, 2024
@gwbrown gwbrown added :Search/Search Search-related issues that do not fall into other categories and removed needs:triage Requires assignment of a team area label labels Jun 11, 2024
@elasticsearchmachine elasticsearchmachine added the Team:Search Meta label for search team label Jun 11, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search (Team:Search)

@benwtrent
Copy link
Member

! indicates NOT in query_string. You might want to escape it if you don't want it to be parsed as such: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#_boolean_operators

Additionally, the indexed terms with the default analyzer will actually be:

{
  "tokens": [
    {
      "token": "04v5",
      "start_offset": 0,
      "end_offset": 4,
      "type": "<ALPHANUM>",
      "position": 0
    },
    {
      "token": "j20240506104423001",
      "start_offset": 5,
      "end_offset": 23,
      "type": "<ALPHANUM>",
      "position": 1
    },
    {
      "token": "1",
      "start_offset": 24,
      "end_offset": 25,
      "type": "<NUM>",
      "position": 2
    },
    {
      "token": "130322198402082311",
      "start_offset": 26,
      "end_offset": 44,
      "type": "<NUM>",
      "position": 3
    }
  ]
}

So, I am not sure you want the ! at all in your query?

@benwtrent benwtrent removed the >bug label Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team
Projects
None yet
Development

No branches or pull requests

4 participants