span-field-masking-query.asciidoc 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. [[query-dsl-span-field-masking-query]]
  2. === Span Field Masking Query
  3. 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`
  4. This can be used to support queries like `span-near` or `span-or` across different fields, which is not ordinarily permitted.
  5. 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.
  6. Example:
  7. [source,js]
  8. --------------------------------------------------
  9. GET /_search
  10. {
  11. "query": {
  12. "span_near": {
  13. "clauses": [
  14. {
  15. "span_term": {
  16. "text": "quick brown"
  17. }
  18. },
  19. {
  20. "field_masking_span": {
  21. "query": {
  22. "span_term": {
  23. "text.stems": "fox"
  24. }
  25. },
  26. "field": "text"
  27. }
  28. }
  29. ],
  30. "slop": 5,
  31. "in_order": false
  32. }
  33. }
  34. }
  35. --------------------------------------------------
  36. // CONSOLE
  37. 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.