Span field masking query

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

This can be used to support queries like span-near or span-or across different fields, which is not ordinarily permitted.

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.

Example:

  1. GET /_search
  2. {
  3. "query": {
  4. "span_near": {
  5. "clauses": [
  6. {
  7. "span_term": {
  8. "text": "quick brown"
  9. }
  10. },
  11. {
  12. "field_masking_span": {
  13. "query": {
  14. "span_term": {
  15. "text.stems": "fox"
  16. }
  17. },
  18. "field": "text"
  19. }
  20. }
  21. ],
  22. "slop": 5,
  23. "in_order": false
  24. }
  25. }
  26. }

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.