Elasticsearch Span Query span query

ES development based on Lucene, and therefore also inherited some diversification of Lucene query, such as Benpian said Span Query span query is based on the Lucene Query SpanTermQuery and other DSL package out, then look at all these DSL how to use it!

More translate Reference: elasticsearch knowledge summary

span_term inquiry

This query if used alone, the effect is similar with the query term, but in general, or for other sub-span query query.

Usage is very simple, only you need to specify the field to the query:

{
    "span_term" : { "user" : "kimchy" }
}

In addition, you can specify multiple query the scores:

{
    "span_term" : { "user" : { "value" : "kimchy", "boost" : 2.0 } }
}

span_multi inquiry

span_multi can wrap a multi_term query, such as wildcard, fuzzy, prefix, term, range or regexp, etc., packaged them as a span query.

Usage is relatively simple, nested inside an ordinary multi_term queries on the line:

{
    "span_multi":{
        "match":{
            "prefix" : { "user" :  { "value" : "ki" } }
        }
    }
}

You can also use boost multiplied by the score, to change the query results Score:

{
    "span_multi":{
        "match":{
            "prefix" : { "user" :  { "value" : "ki", "boost" : 1.08 } }
        }
    }
}

span_first inquiry

This query word is used to determine a position offset with respect to the starting position, for example:

If the contents of a document field is: "hello, my name is tom", we want to retrieve tom, then it should be a minimum of span_first 5, otherwise it can not find.

When in use, just one more than span_term end defining it:

{
    "span_first" : {
        "match" : {
            "span_term" : { "user" : "kimchy" }
        },
        "end" : 3
    }
}

span_near inquiry

This query is mainly used to determine the distance between several span_term, commonly used to retrieve some neighboring words, to avoid interfering with the final result of the search in a global cross-field.

Query is mainly composed of two parts, one part is nested sub-query span, the other part is the greatest span between them

{
    "span_near" : {
        "clauses" : [
            { "span_term" : { "field" : "value1" } },
            { "span_term" : { "field" : "value2" } },
            { "span_term" : { "field" : "value3" } }
        ],
        "slop" : 12,
        "in_order" : false,
        "collect_payloads" : false
    }
}

In the above example, value1, value2, value3 longest span not exceed 12.

span_or inquiry

This query will be nested several sub-queries, the logical relationship between the sub-query or

{
    "span_or" : {
        "clauses" : [
            { "span_term" : { "field" : "value1" } },
            { "span_term" : { "field" : "value2" } },
            { "span_term" : { "field" : "value3" } }
        ]
    }
}

span_not inquiry

This query with respect to span_or, is to exclude the meaning. But within it there are several properties, include a span query definition included; exclude a definition excludes the span query

{
    "span_not" : {
        "include" : {
            "span_term" : { "field1" : "hoya" }
        },
        "exclude" : {
            "span_near" : {
                "clauses" : [
                    { "span_term" : { "field1" : "la" } },
                    { "span_term" : { "field1" : "hoya" } }
                ],
                "slop" : 0,
                "in_order" : true
            }
        }
    }
}

span_containing inquiry

The internal inquiry will have multiple sub-queries, but will set a higher priority sub-queries, a greater role to specify keyword little and big.

{
    "span_containing" : {
        "little" : {
            "span_term" : { "field1" : "foo" }
        },
        "big" : {
            "span_near" : {
                "clauses" : [
                    { "span_term" : { "field1" : "bar" } },
                    { "span_term" : { "field1" : "baz" } }
                ],
                "slop" : 5,
                "in_order" : true
            }
        }
    }
}

span_within inquiry

This query span_containing query role similar, but span_containing is based on lucene in SpanContainingQuery, and span_within is based SpanWithinQuery.

Reproduced in: https: //my.oschina.net/u/204616/blog/545032

Guess you like

Origin blog.csdn.net/weixin_34320159/article/details/91990177