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

Bug Span near query: "Less than 2 subSpans.size():1" #25630

Closed
juretta opened this issue Jul 10, 2017 · 3 comments
Closed

Bug Span near query: "Less than 2 subSpans.size():1" #25630

juretta opened this issue Jul 10, 2017 · 3 comments
Assignees
Labels
>enhancement :Search/Search Search-related issues that do not fall into other categories

Comments

@juretta
Copy link

juretta commented Jul 10, 2017

Elasticsearch version: 5.5.0 (docker.elastic.co/elasticsearch/elasticsearch:5.5.0)

Description:

The documentation for the span near query states:

The clauses element is a list of one or more other span type queries

(emphasis mine)

Just supplying one clause though, causes an error to be returned iff the HTTP request method is POST instead of GET. E.g.

...
    "failures": [
      {
        "shard": 0,
        "index": "test",
        "node": "...",
        "reason": {
          "type": "illegal_argument_exception",
          "reason": "Less than 2 subSpans.size():1"
        }
      }
    ]

Steps to reproduce:

With ES 5.5.0 running:

  1. Create a mapping:
curl -X "PUT" "http://localhost:9200/test" \
     -H "Content-Type: text/plain; charset=utf-8" \
     -u elastic:changeme \
     -d $'{
  "settings": {
    "analysis": {
      "analyzer": {
        "my_analyzer": {
          "tokenizer": "my_pattern_tokenizer"
        }
      },
      "tokenizer": {
        "my_pattern_tokenizer": {
          "type": "pattern",
          "pattern": "\\\\/"
        }
      }
    }
  },
  "mappings": {
    "bar": {
      "properties": {
        "path": {
          "type": "text",
          "analyzer": "my_analyzer"
        }
      }
    }
  }
}'
  1. Add an example document:
curl -X "POST" "http://localhost:9200/test/bar" \
     -H "Content-Type: application/json" \
     -u elastic:changeme \
     -d $'{
  "path": "foo/bar/baz"
}'
  1. Run a search using a span near query with a single clause:
curl -X "POST" "http://localhost:9200/test/bar/_search" \
     -H "Content-Type: application/json" \
     -u elastic:changeme \
     -d $'{
  "query": {
    "span_near": {
      "clauses": [
        {
          "span_first": {
            "match": {
              "span_term": {
                "path": "foo"
              }
            },
            "end": 1
          }
        }
      ],
      "slop": 2,
      "in_order": true
    }
  }
}'

If using an HTTP POST this fails with:

...
    "failures": [
      {
        "shard": 1,
        "index": "test",
        "node": "24CCgJNwRbCoxUlUbFXiuw",
        "reason": {
          "type": "illegal_argument_exception",
          "reason": "Less than 2 subSpans.size():1"
        }
      }
    ]
...

The same request using a GET request method succeeds.

According to https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html it should be possible to use either POST or GET.

GET vs. POST was just a red herring. This fails in either case.

@cbuescher
Copy link
Member

I cannot reproduce the difference between GET/POST you report. I also get the failure you are seeing, I think this might be an error in the documentation for the span near query. My understanding from reading the SpanNearQuery Lucene is that it always requires at least two clauses. Maybe @jpountz or @jimczi can confirm this? In this case we should update the documentation and maybe throw an error earlier in the Elasticsearch query builder if we only have one clause.

@cbuescher cbuescher added :Query DSL >docs General docs changes labels Jul 10, 2017
@jimczi
Copy link
Contributor

jimczi commented Jul 10, 2017

I think it should be handled automatically in ES. I fixed the auto-generated case where another query creates a SpanNearQuery with a single clause but I did not change the SpanNearQueryBuilder itself.
We could also fix this in Lucene since I am not sure why it throws an error instead of just rewriting the query internally. I'll check

@juretta
Copy link
Author

juretta commented Jul 10, 2017

Ok, my bad. My test client (Paw) didn't actually sent the request body. Just using curl (as I added as an example, doh) does show that it fails regardless whether it is GET or POST. So I see the same @cbuescher is seeing.

Sorry for the confusion.

@juretta juretta changed the title Bug Span near query: "Less than 2 subSpans.size():1" with POST request body search Bug Span near query: "Less than 2 subSpans.size():1" Jul 10, 2017
@javanna javanna added >enhancement and removed >docs General docs changes labels Jul 12, 2017
jimczi added a commit to jimczi/elasticsearch that referenced this issue Jul 24, 2017
…use is provided

This change handles the case where a SpanNearQueryBuilder tries to create a query with a single clause.
This is not allowed in the SpanNearQuery so instead of throwing an exception when the weight is built, this change builds and returns
the singleton inner clause on toQuery.

Fixes elastic#25630
jimczi added a commit that referenced this issue Jul 24, 2017
…use is provided (#25856)

This change handles the case where a SpanNearQueryBuilder tries to create a query with a single clause.
This is not allowed in the SpanNearQuery so instead of throwing an exception when the weight is built, this change builds and returns
the singleton inner clause on toQuery.

Fixes #25630
jimczi added a commit that referenced this issue Jul 24, 2017
…use is provided (#25856)

This change handles the case where a SpanNearQueryBuilder tries to create a query with a single clause.
This is not allowed in the SpanNearQuery so instead of throwing an exception when the weight is built, this change builds and returns
the singleton inner clause on toQuery.

Fixes #25630
@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
>enhancement :Search/Search Search-related issues that do not fall into other categories
Projects
None yet
Development

No branches or pull requests

5 participants