span-field-masking-query.asciidoc 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. [[query-dsl-span-field-masking-query]]
  2. === Span field masking query
  3. ++++
  4. <titleabbrev>Span field masking</titleabbrev>
  5. ++++
  6. Wrapper to allow span queries to participate in composite single-field span queries by 'lying' about their search field. The span field masking query maps to Lucene's `SpanFieldMaskingQuery`
  7. This can be used to support queries like `span-near` or `span-or` across different fields, which is not ordinarily permitted.
  8. Span field masking query is invaluable in conjunction with *multi-fields* when same content is indexed with multiple analyzers. For instance we could index a field with the standard analyzer which breaks text up into words, and again with the english analyzer which stems words into their root form.
  9. Example:
  10. [source,console]
  11. --------------------------------------------------
  12. GET /_search
  13. {
  14. "query": {
  15. "span_near": {
  16. "clauses": [
  17. {
  18. "span_term": {
  19. "text": "quick brown"
  20. }
  21. },
  22. {
  23. "field_masking_span": {
  24. "query": {
  25. "span_term": {
  26. "text.stems": "fox"
  27. }
  28. },
  29. "field": "text"
  30. }
  31. }
  32. ],
  33. "slop": 5,
  34. "in_order": false
  35. }
  36. }
  37. }
  38. --------------------------------------------------
  39. Note: as span field masking query returns the masked field, scoring will be done using the norms of the field name supplied. This may lead to unexpected scoring behaviour.