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

simple_query_string returns nothing for "*" search #10632

Closed
pierrre opened this issue Apr 16, 2015 · 15 comments
Closed

simple_query_string returns nothing for "*" search #10632

pierrre opened this issue Apr 16, 2015 · 15 comments
Assignees
Labels
>bug discuss good first issue low hanging fruit :Search/Search Search-related issues that do not fall into other categories stalled

Comments

@pierrre
Copy link

pierrre commented Apr 16, 2015

My simple_query_string returns nothing with "*" search.

If I use a query_string, it works (it returns hits).
The fields and analyzer are the same.

If I wrap my simple_query_string with a bool+must (or should) query, it works. (???)

Is it a bug?

Elasticsearch version: 1.5.1

@dakrone
Copy link
Member

dakrone commented Apr 16, 2015

I believe this may be related to #9866, which was fixed in Lucene 5.1 (see: https://issues.apache.org/jira/browse/LUCENE-6298). I'll look and see whether it is the same issue.

@pierrre
Copy link
Author

pierrre commented Apr 16, 2015

My Lucene version is 4.10.4.

What should happen if I search "*" with a simple_query_string?
Return all docs or nothing?
The query_string returns all docs.

@clintongormley
Copy link

This has been fixed. * will return all docs

@pierrre
Copy link
Author

pierrre commented Jan 17, 2016

Thank you!

@pierrre
Copy link
Author

pierrre commented Feb 5, 2016

Actually, this search:

{
  "fields": [],
  "query": {
    "simple_query_string": {
      "fields": [
        "shortDescription"
      ],
      "query": "*"
    }
  }
}

returns nothing with Elasticsearch 2.2

@clintongormley is the fix for this issue released?

@clintongormley
Copy link

Initially I thought this might be related to #13214 but no, a query string of "*" doesn't match any docs, with or without custom fields:

PUT t/t/1
{}

GET t/_search
{
  "query": {
    "simple_query_string": {
      "query": "*"
    }
  }
}

GET _validate/query?explain
{
  "query": {
    "simple_query_string": {
      "query": "*"
    }
  }
}

The explanation returned by the last request is simply ""

@cbuescher
Copy link
Member

I looked into this a bit by adding an IT test. It looks like Lucenes SimpleQueryParser only recognizes a terms with a closing '*' as prefix query. A single wildcard without leading charactes is treated as a regular term in SimpleQueryParser#consumeToken(). This might even be the intended behaviour. For query_string the situation is different since it uses MapperQueryParser internally which has an allowLeadingWildcard option. Maybe @jimferenczi or @dakrone have an opinion on whether this can or should be fixed in SimpleQueryParser or is even intended.

@dakrone
Copy link
Member

dakrone commented Sep 16, 2016

@cbuescher personally I think a SQS query for * should be internally rewritten to a MatchAllDocsQuery, which I think means this would go into Lucene. If people agree I can work on a patch for the next Lucene release

@clintongormley
Copy link

@dakrone not so sure - should it be match all or should it match all docs that have a value for the specified fields? See #13214 for a similar discussion

@dakrone
Copy link
Member

dakrone commented Sep 26, 2016

@clintongormley ahh okay, in light of that discussion:

"*" always means match all documents
"field:*" means find all documents that contain a non-null value in the field (incl empty string)

Since simple_query_string can either use the default_field or have fields
specified, I'm thinking we should do:

  • If query is "*" and no fields are specified, treat it as match all
    documents
  • If query is "*" and fields are specified, query is essentially field1:* OR field2:* OR field3:* which matches documents that have non-null values in
    the field

Do you think that'd be a better solution?

@clintongormley
Copy link

@dakrone Given that the end user can't specify fields in the SQS like you can in QS (user:kimchy) I've come around to thinking that * should always mean match all docs.

@dakrone
Copy link
Member

dakrone commented Oct 11, 2016

I opened https://issues.apache.org/jira/browse/LUCENE-7490 for this with a patch

@dakrone
Copy link
Member

dakrone commented Oct 12, 2016

Looks like this will be in Lucene 6.3, so I'm marking this as "stalled" until 6.3 is released and incorporated.

@dakrone dakrone self-assigned this Oct 12, 2016
@weberhofer
Copy link

I think this issue has been solved with ES 5.3

@cbuescher
Copy link
Member

@weberhofer thanks a lot, I just checked with 5.1 (which is based in Lucene 6.3) and 5.2 and it seems to be fixed. I will close this.

@clintongormley clintongormley added :Search/Search Search-related issues that do not fall into other categories and removed :Query DSL labels Feb 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug discuss good first issue low hanging fruit :Search/Search Search-related issues that do not fall into other categories stalled
Projects
None yet
Development

No branches or pull requests

5 participants