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

Query DSL: span_near query not working #2994

Closed
iksnalybok opened this Issue May 6, 2013 · 3 comments

Comments

Projects
None yet
3 participants
@iksnalybok
Copy link
Contributor

commented May 6, 2013

Hi,

Making a simple span_near query just fails. Running
query: span_near : { clauses : [ { span_term : { index.field : value } } ] }
I get
QueryParsingException[[index] spanNear [clauses] must be of type span query]
I don't get any error if I put an unknown field.

NB I'm using version 0.90.0.

By looking at https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/index/query/SpanTermQueryParser.java

      33. import static org.elasticsearch.index.query.support.QueryParsers.wrapSmartNameQuery;
     106. SpanTermQuery query = new SpanTermQuery(new Term(fieldName, valueBytes));
     108. return wrapSmartNameQuery(query, smartNameFieldMappers, parseContext);

I supposed that QueryParsers#wrapSmartNameQuery() does not return a span query (but a XFilteredQuery).

To reproduce (bash):

HOSTPORT="127.0.0.1:9200"

function create_schema () {
    local SCHEMA='
{
    "mappings" : {
        "bugnearspanindex" : {
            "properties" : {
                "myField" : { "type" : "string" }
            }
        }
    }
}
'
    curl --noproxy '*' -XPUT "http://${HOSTPORT}/bugnearspanindex/" -d "${SCHEMA}"
}


function make_and_run_query () {
    local FIELD=$1
    local QUERY='
{
    "query" : {
        "span_near" : {
            "clauses" : [
                { "span_term" : { "bugnearspanindex.'${FIELD}'" : "foobar" } }
            ],
            "slop" : 0,
            "in_order" : false,
            "collect_payloads" : false
        }
    }
}
'
    curl --noproxy '*' -XGET "http://${HOSTPORT}/bugnearspanindex/_search?pretty=true&format=yaml" -d "${QUERY}"
}

# create the schema
create_schema

# run the request on a non existing field
make_and_run_query nonExistingField
  # -> hits: { total: 0 }

# run the request on an existing field
make_and_run_query myField
  # -> error: QueryParsingException[[bugnearspanindex] spanNear [clauses] must be of type span query]
@s1monw

This comment has been minimized.

Copy link
Contributor

commented May 7, 2013

hey, the reason why this fails for you is because you explicitly specify the type in the field name. index.field will trigger a Filter that is wrapped around the SpanTermQuery for the type index. Yet, this is obviously not correct but it might help you to work around the issue for now.

@ghost ghost assigned s1monw May 7, 2013

@s1monw

This comment has been minimized.

Copy link
Contributor

commented May 7, 2013

I think the solution here is really not trying to wrap in a filter at all. This won't really work with spans anyways so that is not even a backwards break.

@kimchy

This comment has been minimized.

Copy link
Member

commented May 7, 2013

@s1monw +1, I think this fix makes tons of sense.

@s1monw s1monw closed this in c1e8d47 May 7, 2013

s1monw added a commit that referenced this issue May 7, 2013

Don't use smart query wrapping for span term query
Lucenes span queries are a different family than 'ordinary' queries
in lucene. Spans only work with other spans such that smart query
wrapping doesn't work with span queries at all ie. we can't wrap
in filtered query.

Closes #2994

mute pushed a commit to mute/elasticsearch that referenced this issue Jul 29, 2015

Don't use smart query wrapping for span term query
Lucenes span queries are a different family than 'ordinary' queries
in lucene. Spans only work with other spans such that smart query
wrapping doesn't work with span queries at all ie. we can't wrap
in filtered query.

Closes elastic#2994
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.