Span Near Query Usage

edit

Fluent DSL example

edit
q
.SpanNear(sn => sn
    .Name("named_query")
    .Boost(1.1)
    .Clauses(
        c => c.SpanTerm(st => st.Field("field").Value("value1")),
        c => c.SpanTerm(st => st.Field("field").Value("value2")),
        c => c.SpanTerm(st => st.Field("field").Value("value3")),
        c => c.SpanGap(st => st.Field("field").Width(2))
    )
    .Slop(12)
    .InOrder()
)

Object Initializer syntax example

edit
new SpanNearQuery
{
    Name = "named_query",
    Boost = 1.1,
    Clauses = new List<ISpanQuery>
    {
        new SpanQuery { SpanTerm = new SpanTermQuery { Field = "field", Value = "value1" } },
        new SpanQuery { SpanTerm = new SpanTermQuery { Field = "field", Value = "value2" } },
        new SpanQuery { SpanTerm = new SpanTermQuery { Field = "field", Value = "value3" } },
        new SpanQuery { SpanGap = new SpanGapQuery { Field = "field", Width = 2 } }
    },
    Slop = 12,
    InOrder = true,
}

Example json output.

{
  "span_near": {
    "clauses": [
      {
        "span_term": {
          "field": {
            "value": "value1"
          }
        }
      },
      {
        "span_term": {
          "field": {
            "value": "value2"
          }
        }
      },
      {
        "span_term": {
          "field": {
            "value": "value3"
          }
        }
      },
      {
        "span_gap": {
          "field": 2
        }
      }
    ],
    "slop": 12,
    "in_order": true,
    "_name": "named_query",
    "boost": 1.1
  }
}