span-not-query.asciidoc 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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,console]
  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. The `include` and `exclude` clauses can be any span type query. The
  34. `include` clause is the span query whose matches are filtered, and the
  35. `exclude` clause is the span query whose matches must not overlap those
  36. returned.
  37. In the above example all documents with the term hoya are filtered except the ones that have 'la' preceding them.
  38. Other top level options:
  39. [horizontal]
  40. `pre`:: If set the amount of tokens before the include span can't have overlap with the exclude span. Defaults to 0.
  41. `post`:: If set the amount of tokens after the include span can't have overlap with the exclude span. Defaults to 0.
  42. `dist`:: If set the amount of tokens from within the include span can't have overlap with the exclude span. Equivalent
  43. of setting both `pre` and `post`.