span-not-query.asciidoc 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. [[query-dsl-span-not-query]]
  2. === Span Not Query
  3. Removes matches which overlap with another span query or which are
  4. within x tokens before (controlled by the parameter `pre`) or y tokens
  5. after (controlled by the parameter `post`) another SpanQuery. The span not
  6. query maps to Lucene `SpanNotQuery`. Here is an example:
  7. [source,js]
  8. --------------------------------------------------
  9. GET /_search
  10. {
  11. "query": {
  12. "span_not" : {
  13. "include" : {
  14. "span_term" : { "field1" : "hoya" }
  15. },
  16. "exclude" : {
  17. "span_near" : {
  18. "clauses" : [
  19. { "span_term" : { "field1" : "la" } },
  20. { "span_term" : { "field1" : "hoya" } }
  21. ],
  22. "slop" : 0,
  23. "in_order" : true
  24. }
  25. }
  26. }
  27. }
  28. }
  29. --------------------------------------------------
  30. // CONSOLE
  31. The `include` and `exclude` clauses can be any span type query. The
  32. `include` clause is the span query whose matches are filtered, and the
  33. `exclude` clause is the span query whose matches must not overlap those
  34. returned.
  35. In the above example all documents with the term hoya are filtered except the ones that have 'la' preceding them.
  36. Other top level options:
  37. [horizontal]
  38. `pre`:: If set the amount of tokens before the include span can't have overlap with the exclude span. Defaults to 0.
  39. `post`:: If set the amount of tokens after the include span can't have overlap with the exclude span. Defaults to 0.
  40. `dist`:: If set the amount of tokens from within the include span can't have overlap with the exclude span. Equivalent
  41. of setting both `pre` and `post`.