span-not-query.asciidoc 1.7 KB

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