跨度邻近查询

编辑

匹配彼此邻近的跨度。可以指定slop,即允许的最大不匹配位置数,以及是否需要按顺序匹配。这是一个示例

resp = client.search(
    query={
        "span_near": {
            "clauses": [
                {
                    "span_term": {
                        "field": "value1"
                    }
                },
                {
                    "span_term": {
                        "field": "value2"
                    }
                },
                {
                    "span_term": {
                        "field": "value3"
                    }
                }
            ],
            "slop": 12,
            "in_order": False
        }
    },
)
print(resp)
response = client.search(
  body: {
    query: {
      span_near: {
        clauses: [
          {
            span_term: {
              field: 'value1'
            }
          },
          {
            span_term: {
              field: 'value2'
            }
          },
          {
            span_term: {
              field: 'value3'
            }
          }
        ],
        slop: 12,
        in_order: false
      }
    }
  }
)
puts response
const response = await client.search({
  query: {
    span_near: {
      clauses: [
        {
          span_term: {
            field: "value1",
          },
        },
        {
          span_term: {
            field: "value2",
          },
        },
        {
          span_term: {
            field: "value3",
          },
        },
      ],
      slop: 12,
      in_order: false,
    },
  },
});
console.log(response);
GET /_search
{
  "query": {
    "span_near": {
      "clauses": [
        { "span_term": { "field": "value1" } },
        { "span_term": { "field": "value2" } },
        { "span_term": { "field": "value3" } }
      ],
      "slop": 12,
      "in_order": false
    }
  }
}

clauses 元素是一个或多个其他跨度类型查询的列表,而 slop 控制允许的最大不匹配位置数。