目录

Query DSL - Span queries

优质
小牛编辑
131浏览
2023-12-01

Span queries

  • span_term查询

等同于 term query ,但与其他Span查询一起使用。

查看 Span Term Query

  1. QueryBuilder qb = spanTermQuery(
  2. "user", //field
  3. "kimchy" //value
  4. );
  • span_multi查询

包含term, range, prefix, wildcard, regexp 或者 fuzzy 查询。

查看Span Multi Term Query

  1. QueryBuilder qb = spanMultiTermQueryBuilder(
  2. prefixQuery("user", "ki") //可以是MultiTermQueryBuilder 的 扩展 比如:FuzzyQueryBuilder, PrefixQueryBuilder, RangeQueryBuilder, RegexpQueryBuilder , WildcardQueryBuilder。
  3. );
  • span_first查询

接受另一个Span查询,其匹配必须出现在字段的前N个位置。

查看Span First Query

  1. QueryBuilder qb = spanFirstQuery(
  2. spanTermQuery("user", "kimchy"), //query
  3. 3 //max end position
  4. );
  • span_near查询

接受多个Span查询,其匹配必须在彼此的指定距离内,并且可能顺序相同。

查看Span Near Query

  1. QueryBuilder qb = spanNearQuery(
  2. spanTermQuery("field","value1"), //span term queries
  3. 12) //slop factor: the maximum number of intervening unmatched positions
  4. .addClause(spanTermQuery("field","value2")) //span term queries
  5. .addClause(spanTermQuery("field","value3")) //span term queries
  6. .inOrder(false); //whether matches are required to be in-order
  • span_or查询

组合多个Span查询 - 返回与任何指定查询匹配的文档。

查看Span Or Query

  1. QueryBuilder qb = spanOrQuery(
  2. spanTermQuery("field","value1"))
  3. .addClause(spanTermQuery("field","value2"))
  4. .addClause(spanTermQuery("field","value3")); //span term queries
  • span_not查询

包装另一个Span查询,并排除与该查询匹配的所有文档。

查看Span Not Query

  1. QueryBuilder qb = spanNotQuery(
  2. spanTermQuery("field","value1"), //span query whose matches are filtered
  3. spanTermQuery("field","value2")); //span query whose matches must not overlap those returned
  • span_containing 查询

接受Span查询的列表,但仅返回与第二个Spans查询匹配的Span。

查看 Span Containing Query

  1. QueryBuilder qb = spanContainingQuery(
  2. spanNearQuery(spanTermQuery("field1","bar"), 5) //big part
  3. .addClause(spanTermQuery("field1","baz"))
  4. .inOrder(true),
  5. spanTermQuery("field1","foo")); //little part
  • span_within查询

只要其 span 位于由其他Span查询列表返回的范围内,就会返回单个Span查询的结果,

查看Span Within Query

  1. QueryBuilder qb = spanWithinQuery(
  2. spanNearQuery(spanTermQuery("field1", "bar"), 5) //big part
  3. .addClause(spanTermQuery("field1", "baz"))
  4. .inOrder(true),
  5. spanTermQuery("field1", "foo")); //little part