Elasticsearch Reference
  • Introduction
  • 入门
    • 基本概念
    • 安装
    • 探索集群
      • 集群健康
      • 获取所有索引库
      • 创建一个索引库
      • 索引文档创建与查询
      • 删除索引
    • 修改数据
      • 更新文档
      • 删除文档
      • 批量处理
    • 探索您的数据
      • 搜索API
      • 查询语言介绍
      • 执行搜索
      • 执行过滤
      • 执行聚合
    • 总结
  • Elasticsearch设置
    • 安装Elasticsearch
      • .zip或.tar.gz文件的安装方式
      • Debian软件包安装方式
      • RPM安装方式
      • Windows安装方式
      • Docker安装方式
    • 配置Elasticsearch
    • 重要的Elasticsearch配置
    • 安全配置
    • 启动前检查
      • 堆大小检查
      • 文件描述符检查
      • 内存锁定检查
      • 最大线程数检查
      • 最大虚拟内存检查
      • 最大map数检查
      • JVM检查
      • 串行收集使用检查
      • 系统调用过滤检查
      • OnError与OnOutOfMemroyError检查
      • G1GC检查
    • 重要的系统配置
      • 系统设置
      • 在jvm.options中设置JVM堆大小
      • 禁用swapping
      • 文件描述符
      • 虚拟内存
      • 线程数
    • Elasticsearch升级
      • 滚动升级
      • 全集群重启升级
      • 索引重建升级
    • Elasticsearch停机
  • 重大变更
    • 5.3重大变更
    • 5.2重大变更
      • 删除Shadow副本
    • 5.1重大变更
    • 5.0重大变更
      • 搜索与查询DSL变化
      • Mapping变化
      • Percolator变化
      • Suggester变化
      • Index API变化
      • Document API变化
      • Settings变化
      • Allocation变化
      • HTTP变化
      • REST API变化
      • CAT API变化
      • JAVA API变化
      • 安装包
      • 插件变化
      • 文件系统相关变化
      • 磁盘数据文件路径
      • Aggregation变化
      • 脚本相关变化
  • API约定
    • 多索引语法
    • 索引库名称的日期运算
    • 常用选项
    • URL-based访问控制
  • 文档API
    • 读写文档
    • Index API
    • Get API
    • Delete API
    • Delete By Query API
    • Update API
    • Update By Query API
    • Multi Get API
    • Bulk API
    • Reindex API
    • Term Vectors
    • Multi termvectors API
    • refresh
  • 搜索API
    • Search
    • URI Search
    • Request Body Search
      • Query
      • From / Size
      • Sort
      • Source filtering
      • Fields
      • Script Fields
      • Doc value Fields
      • Post filter
      • Highlighting
      • Rescoring
      • Search Type
      • Scroll
      • Preference
      • Explain
      • Version
      • Index Boost
      • min_score
      • Named Queries
      • Inner hits
      • Field Collapsing
      • Search After
    • Search Template
    • Multi Search Template
    • Search Shards API
    • Suggesters
      • Term suggester
      • Phrase Suggester
      • Completion Suggester
      • Context Suggester
    • Multi Search API
    • Count API
    • Validate API
    • Explain API
    • Profile API
      • Profiling Queries
      • Profiling Aggregations
      • Profiling Considerations
    • Percolator
    • Field stats API
  • 聚合
    • Metrics Aggregations
      • Avg Aggregation
      • Cardinality Aggregation
      • Extended Stats Aggregation
      • Geo Bounds Aggregation
      • Geo Centroid Aggregation
      • Max Aggregation
      • Min Aggregation
      • Percentiles Aggregation
      • Percentile Ranks Aggregation
      • Scripted Metric Aggregation
      • Stats Aggregation
      • Sum Aggregation
      • Top hits Aggregation
      • Value Count Aggregation
    • Bucket Aggregations
      • Adjacency Matrix Aggregation
      • Children Aggregation
      • Date Histogram Aggregation
      • Date Range Aggregation
      • Diversified Sampler Aggregation
      • Filter Aggregation
      • Filters Aggregation
      • Geo Distance Aggregation
      • GeoHash grid Aggregation
      • Global Aggregation
      • Histogram Aggregation
      • IP Range Aggregation
      • Missing Aggregation
      • Nested Aggregation
      • Range Aggregation
      • Reverse nested Aggregation
      • Sampler Aggregation
      • Significant Terms Aggregation
      • Terms Aggregation
    • Pipeline Aggregations
      • Avg Bucket Aggregation
      • Derivative Aggregation
      • Max Bucket Aggregation
      • Min Bucket Aggregation
      • Sum Bucket Aggregation
      • Stats Bucket Aggregation
      • Extended Stats Bucket Aggregation
      • Percentiles Bucket Aggregation
      • Moving Average Aggregation
      • Cumulative Sum Aggregation
      • Bucket Script Aggregation
      • Bucket Selector Aggregation
      • Serial Differencing Aggregation
    • Matrix Aggregations
      • Matrix Stats
    • Caching heavy aggregations
    • Returning only aggregation results
    • Aggregation Metadata
  • 索引库API
    • Create Index
    • Delete Index
    • Get Index
    • Indices Exists
    • Open / Close Index API
    • Shrink Index
    • Rollover Index
    • Put Mapping
    • Get Mapping
    • Get Field Mapping
    • Types Exists
    • Index Aliases
    • Update Indices Settings
    • Get Settings
    • Analyze
      • Explain Analyze
    • Index Templates
    • Shadow replica indices
      • Node level settings related to shadow replicas
    • Indices Stats
    • Indices Segments
    • Indices Recovery
    • Indices Shard Stores
    • Clear Cache
    • Flush
      • Synced Flush
    • Refresh
    • Force Merge
  • cat API
    • cat aliases
    • cat allocation
    • cat count
    • cat fielddata
    • cat health
    • cat indices
    • cat master
    • cat nodeattrs
    • cat nodes
    • cat pending tasks
    • cat plugins
    • cat recovery
    • cat repositories
    • cat thread pool
    • cat shards
    • cat segments
    • cat snapshots
    • cat templates
  • 集群API
    • Cluster Health
    • Cluster State
    • Cluster Stats
    • Pending cluster tasks
    • Cluster Reroute
    • Cluster Update Settings
    • Nodes Stats
    • Nodes Info
    • Task Management API
    • Nodes hot_threads
    • Cluster Allocation Explain API
  • DSL查询
    • Query and filter context
    • Match All Query
    • Full text queries
      • Match Query
      • Match Phrase Query
      • Match Phrase Prefix Query
      • Multi Match Query
      • Common Terms Query
      • Query String Query
      • Simple Query String Query
    • Term level queries
      • Term Query
      • Terms Query
      • Range Query
      • Exists Query
      • Prefix Query
      • Wildcard Query
      • Regexp Query
      • Fuzzy Query
      • Type Query
      • Ids Query
    • Compound queries
      • Constant Score Query
      • Bool Query
      • Dis Max Query
      • Function Score Query
      • Boosting Query
      • Indices Query
    • Joining queries
      • Nested Query
      • Has Child Query
      • Has Parent Query
      • Parent Id Query
    • Geo queries
      • GeoShape Query
      • Geo Bounding Box Query
      • Geo Distance Query
      • Geo Distance Range Query
      • Geo Polygon Query
    • Specialized queries
      • More Like This Query
      • Template Query
      • Script Query
      • Percolate Query
    • Span queries
      • Span Term Query
      • Span Multi Term Query
      • Span First Query
      • Span Near Query
      • Span Or Query
      • Span Not Query
      • Span Containing Query
      • Span Within Query
      • Span Field Masking Query
    • Minimum Should Match
    • Multi Term Query Rewrite
  • Mapping
    • Field datatypes
      • Array datatype
      • Binary datatype
      • Range datatypes
      • Boolean datatype
      • Date datatype
      • Geo-point datatype
      • Geo-Shape datatype
      • IP datatype
      • Keyword datatype
      • Nested datatype
      • Numeric datatypes
      • Object datatype
      • String datatype
      • Text datatype
      • Token count datatype
      • Percolator type
    • Meta-Fields
      • _all field
      • _field_names field
      • _id field
      • _index field
      • _meta field
      • _parent field
      • _routing field
      • _source field
      • _type field
      • _uid field
    • Mapping parameters
      • analyzer
      • normalizer
      • boost
      • coerce
      • copy_to
      • doc_values
      • dynamic
      • enabled
      • fielddata
      • format
      • ignore_above
      • ignore_malformed
      • include_in_all
      • index
      • index_options
      • fields
      • norms
      • null_value
      • position_increment_gap
      • properties
      • search_analyzer
      • similarity
      • store
      • term_vector
    • Dynamic Mapping
      • default mapping
      • Dynamic field mapping
      • Dynamic templates
      • Override default template
  • Analysis
    • Anatomy of an analyzer
    • Testing analyzers
    • Analyzers
      • Configuring built-in analyzers
      • Standard Analyzer
      • Simple Analyzer
      • Whitespace Analyzer
      • Stop Analyzer
      • Keyword Analyzer
      • Pattern Analyzer
      • Language Analyzers
      • Fingerprint Analyzer
      • Custom Analyzer
      • Normalizers
    • Tokenizers
      • Standard Tokenizer
      • Letter Tokenizer
      • Lowercase Tokenizer
      • Whitespace Tokenizer
      • UAX URL Email Tokenizer
      • Classic Tokenizer
      • Thai Tokenizer
      • NGram Tokenizer
      • Edge NGram Tokenizer
      • Keyword Tokenizer
      • Pattern Tokenizer
      • Path Hierarchy Tokenizer
    • Token Filters
      • Standard Token Filter
      • ASCII Folding Token Filter
      • Flatten Graph Token Filter
      • Length Token Filter
      • Lowercase Token Filter
      • Uppercase Token Filter
      • NGram Token Filter
      • Edge NGram Token Filter
      • Porter Stem Token Filter
      • Shingle Token Filter
      • Stop Token Filter
      • Word Delimiter Token Filter
      • Stemmer Token Filter
      • Stemmer Override Token Filter
      • Keyword Marker Token Filter
      • Keyword Repeat Token Filter
      • KStem Token Filter
      • Snowball Token Filter
      • Phonetic Token Filter
      • Synonym Token Filter
      • Synonym Graph Token Filter
      • Compound Word Token Filter
      • Reverse Token Filter
      • Elision Token Filter
      • Truncate Token Filter
      • Unique Token Filter
      • Pattern Capture Token Filter
      • Pattern Replace Token Filter
      • Trim Token Filter
      • Limit Token Count Token Filter
      • Hunspell Token Filter
      • Common Grams Token Filter
      • Normalization Token Filter
      • CJK Width Token Filter
      • CJK Bigram Token Filter
      • Delimited Payload Token Filter
      • Keep Words Token Filter
      • Keep Types Token Filter
      • Classic Token Filter
      • Apostrophe Token Filter
      • Decimal Digit Token Filter
      • Fingerprint Token Filter
      • Minhash Token Filter
    • Character Filters
      • HTML Strip Char Filter
      • Mapping Char Filter
      • Pattern Replace Char Filter
  • 模块
    • 集群
      • 集群的分片分配
      • 基于磁盘的分片分配
      • 了解分片分配
      • 分片分配过滤
      • 其他群集设置
    • Discovery
      • Azure Classic Discovery
      • EC2 Discovery
      • Google Compute Engine Discovery
      • Zen Discovery
    • 本地网关
    • HTTP
    • 索引库
      • 熔断
      • Fielddata
      • 节点查询缓存
      • 索引缓冲
      • 分片请求缓存
      • 索引库恢复
    • 网络设置
    • 节点
    • 插件
    • 脚本
      • 如何使用脚本
      • 文档中字段的访问以及一些特殊变量
      • 脚本与安全
      • Groovy脚本语言
      • PainLess脚本语言
      • PainLess语法
      • PainLess调试
      • Lucene表达式语言
      • 原生(java)脚本
      • 高级文本评分脚本
    • 快照与还原
    • 线程池
    • 传输
    • Tribe节点
    • 跨集群搜索
  • Index模块
    • Analysis
    • Index Shard Allocation
      • Shard Allocation Filtering
      • Delaying allocation when a node leaves
      • Index recovery prioritization
      • Total Shards Per Node
    • Mapper
    • Merge
    • Similarity module
    • Slow Log
    • Store
      • Pre-loading data into the file system cache
    • Translog
  • Ingest节点
    • Pipeline Definition
    • Ingest APIs
      • Put Pipeline API
      • Get Pipeline API
      • Delete Pipeline API
      • Simulate Pipeline API
    • Accessing Data in Pipelines
    • Handling Failures in Pipelines
    • Processors
      • Append Processor
      • Convert Processor
      • Date Processor
      • Date Index Name Processor
      • Fail Processor
      • Foreach Processor
      • Grok Processor
      • Gsub Processor
      • Join Processor
      • JSON Processor
      • KV Processor
      • Lowercase Processor
      • Remove Processor
      • Rename Processor
      • Script Processor
      • Set Processor
      • Split Processor
      • Sort Processor
      • Trim Processor
      • Uppercase Processor
      • Dot Expander Processor
  • How To
    • General recommendations
    • Recipes
    • Tune for indexing speed
    • Tune for search speed
    • Tune for disk usage
  • Testing
    • Java Testing Framework
      • why randomized testing?
      • Using the elasticsearch test classes
      • unit tests
      • integration tests
      • Randomized testing
      • Assertions
  • 术语表
  • 发布说明
    • 5.3.0 Release Notes
    • 5.2.2 Release Notes
    • 5.2.1 Release Notes
    • 5.2.0 Release Notes
    • 5.1.2 Release Notes
    • 5.1.1 Release Notes
    • 5.1.0 Release Notes
    • 5.0.2 Release Notes
    • 5.0.1 Release Notes
    • 5.0.0 Combined Release Notes
    • 5.0.0 GA Release Notes
    • 5.0.0-rc1 Release Notes
    • 5.0.0-beta1 Release Notes
    • 5.0.0-alpha5 Release Notes
    • 5.0.0-alpha4 Release Notes
    • 5.0.0-alpha3 Release Notes
    • 5.0.0-alpha2 Release Notes
    • 5.0.0-alpha1 Release Notes
    • 5.0.0-alpha1 Release Notes (Changes previously released in 2.x)
  • Painless API参考文档
Powered by GitBook
On this page
  • API 示例
  • 基本短语 suggest API 参数
  • 平滑(smothing)模型
  • 候选生成器( Generators)
  • 直接生成器(Generators)

Was this helpful?

  1. 搜索API
  2. Suggesters

Phrase Suggester

PreviousTerm suggesterNextCompletion Suggester

Last updated 4 years ago

Was this helpful?

注意

为了理解 suggestions 的形式,请先阅读。

术语 suggester 提供了一种非常方便的 API ,以在某个字符串距离内在每个 token 的基础上访问字替换。 API 允许单独访问流中的每个 token ,而 suggest 选择由API使用者选择。 然而,通常需要预先选择的 suggestions 以呈现给最终用户。 短语 suggester 在 term suggester 之上添加额外的逻辑以选择整个经校正的短语,而不是基于 ngram-language 模型加权的单个 token 。 在实践中,这个 suggester 将能够基于共现和频率来做出关于选择哪些 token 的更好的决定。

API 示例

一般来说,phrase suggester 需要前面的特殊映射。 此页面上的 phrase suggester 示例需要以下映射才能正常工作。 仅在最后一个示例中使用反向(reverse)分析器。

PUT test
{
  "settings": {
    "index": {
      "number_of_shards": 1,
      "analysis": {
        "analyzer": {
          "trigram": {
            "type": "custom",
            "tokenizer": "standard",
            "filter": ["standard", "shingle"]
          },
          "reverse": {
            "type": "custom",
            "tokenizer": "standard",
            "filter": ["standard", "reverse"]
          }
        },
        "filter": {
          "shingle": {
            "type": "shingle",
            "min_shingle_size": 2,
            "max_shingle_size": 3
          }
        }
      }
    }
  },
  "mappings": {
    "test": {
      "properties": {
        "title": {
          "type": "text",
          "fields": {
            "trigram": {
              "type": "text",
              "analyzer": "trigram"
            },
            "reverse": {
              "type": "text",
              "analyzer": "reverse"
            }
          }
        }
      }
    }
  }
}
POST test/test?refresh=true
{"title": "noble warriors"}
POST test/test?refresh=true
{"title": "nobel prize"}

一旦你设置了分析器和映射,你可以在同一个地方使用 phrase suggester,你可以使用 term suggester :

POST test/_search
{
  "suggest": {
    "text": "noble prize",
    "simple_phrase": {
      "phrase": {
        "field": "title.trigram",
        "size": 1,
        "gram_size": 3,
        "direct_generator": [ {
          "field": "title.trigram",
          "suggest_mode": "always"
        } ],
        "highlight": {
          "pre_tag": "<em>",
          "post_tag": "</em>"
        }
      }
    }
  }
}

该响应包含由最可能的拼写纠正评分的 suggestions 。 在这种情况下,我们收到了预期的校正“诺贝尔奖”。

{
  "_shards": ...
  "hits": ...
  "timed_out": false,
  "took": 3,
  "suggest": {
    "simple_phrase" : [
      {
        "text" : "noble prize",
        "offset" : 0,
        "length" : 11,
        "options" : [ {
          "text" : "nobel prize",
          "highlighted": "<em>nobel</em> prize",
          "score" : 0.5962314
        }]
      }
    ]
  }
}

基本短语 suggest API 参数

参数

描述

field

用于对语言模型进行n元语法查找的字段的名称, suggester 将使用此字段获取统计信息以对校正进行评分。 此字段是必填字段。

gram_size

在字段中设置 n-gram(shingles)的最大大小。 如果字段不包含 n-gram(shingles),则应省略或设置为1.请注意,Elasticsearch 尝试根据指定的字段检测克大小。 如果字段使用 shingle 过滤器,则如果未明确设置,则将gram_size 设置为 max_shingle_size。

real_word_error_likelihood

即使词语存在于字典中,词语是拼写错误的可能性。 默认是0.95对应5%的真实单词拼写错误。

confidence

置信水平定义了应用于输入短语分数的因子,其被用作其他 suggest 候选的阈值。 只有得分高于阈值的候选人才会包括在结果中。 例如,1.0的置信水平将仅返回得分高于输入短语的 suggestions 。 如果设置为0.0,则返回前N个候选。 默认值为1.0。

max_errors

为了形成校正,最多被认为是拼写错误的术语的最大百分比。 此方法接受范围[0..1]中的浮点值作为实际查询项的分数或作为查询项的绝对数量的数字> = 1。 默认值设置为1.0,对应于只返回最多1个拼写错误项的更正。 请注意,将其设置过高可能会对性能产生负面影响。 推荐使用低值,例如1或2,否则 suggestions 调用的时间花费可能超过查询执行的时间花费。

separator

用于分隔 bigram 字段中的术语的分隔符。 如果未设置,则使用空格字符作为分隔符

size

为每个单独查询项生成的候选数量低数字(如3或5)通常会产生良好的结果。 提高这个可以带来更高的编辑距离的术语。 默认值为5。

analyzer

将分析器设置为分析以使用 suggest 文本。 默认为通过字段传递的 suggest 字段的搜索分析器。

shard_size

设置要从每个单独的分片检索的 suggestions 字词的最大数量。 在减少阶段期间,基于size选项只返回前N个 suggestions 。 默认为5。

text

设置文本/查询以提供 suggestions 。

highlight

设置 suggestion 高亮显示。 如果未提供,则不返回高亮显示的字段。 如果提供,必须包含完全pre_tag和post_tag包裹改变的标记。 如果一行中的多个标记被改变,则改变的标记的整个短语被包装,而不是每个标记。

collate

检查针对指定查询的每个 suggestion ,以修剪索引中没有匹配的文档的 suggestions 。 对于 suggestion 的整理查询仅在从中生成 suggestion 的本地碎片上运行。 必须指定查询,并将其作为模板查询运行。 当前 suggestion 自动提供为 } 变量,应在您的查询中使用。 您仍然可以指定自己的模板 params-suggestions 值将添加到您指定的变量。 此外,您可以指定一个 prune 以控制是否返回所有短语 suggestions ,设置为 true时, suggestions 将有一个附加选项 collate_match,如果找到匹配的短语文档,则为true,否则为false。 prune 的默认值为false。

POST _search
{
  "suggest": {
    "text" : "noble prize",
    "simple_phrase" : {
      "phrase" : {
        "field" :  "title.trigram",
        "size" :   1,
        "direct_generator" : [ {
          "field" :            "title.trigram",
          "suggest_mode" :     "always",
          "min_word_length" :  1
        } ],
        "collate": {
          "query": { # ①
            "inline" : {
              "match": {
                "{{field_name}}" : "{{suggestion}}"  # ②
              }
            }
          },
          "params": {"field_name" : "title"},  # ③
          "prune": true # ④
        }
      }
    }
  }
}

① 所有这三个元素都是可选的。

② 变量将会被每个 suggestion 文本所代替。

③ 额外的 field_name 变量已经在 params 中被指定,并且被 match 查询所使用。

④ 所有的 suggestions 将和一个额外的 collate_match 选项一起返回,表示是否生成的短语匹配任何文档。

平滑(smothing)模型

短语 suggester 支持多个平滑模型来平衡重量不频繁grams(grams(瓦)不存在于索引中)和频繁 grams(在索引中至少出现一次)。

stupid_backoff 简单的回退模型,如果高阶计数为0并且通过常数因子折扣低阶n-gram模型,则回退到低阶n-gram模型。 默认折扣为0.4。 Stupid Backoff是默认模型。

laplace 使用添加平滑的平滑模型,其中将常数(通常为1.0或更小)添加到所有计数以平衡权重。默认α为0.5。

linear_interpolation 平滑模型,其基于用户提供的权重(lambdas)获取单字组,双字组和三字母组的加权平均值。 线性插值没有任何默认值。 必须提供所有参数(trigram_lambda,bigram_lambda,unigram_lambda)。

候选生成器( Generators)

短语 suggester 使用候选生成器来产生给定文本中每个术语的可能术语的列表。 单个候选生成器类似于对文本中的每个单独术语调用的术语 suggester 。 生成器的输出随后与来自其他项的候选一起被评分以用于 suggestions 候选。

目前只支持一种类型的候选生成器,direct_generator。 Phrase suggestions API接受在关键direct_generator下的生成器列表,列表中的每个生成器在原始文本中被称为每个term。

直接生成器(Generators)

直接生成器支持以下参数:

参数

描述

field

从中获取候选 suggestions 的字段。 这是必需的选项,需要设置全局或每个 suggestion 。

size

每个 suggestion 文本标记返回的最大更正值。

suggest_mode

suggest 模式控制在每个分片上生成的 suggestions 中包括哪些 suggestions 。 除了always之外的所有值都可以被认为是优化以生成更少的 suggestions 以在每个碎片上测试,并且在组合在每个碎片上生成的 suggestions 时不被重新检查。 因此,对于不包含它们的分片,即使其他分片包含它们,也会生成对分片的 suggestions 。 这些应该使用信心过滤掉。 可以指定三个可能的值: missing: 仅生成不在f中的术语的 suggestions 。 这是默认值。 popular: 只 suggest 在 shard 的更多文档中出现的术语,而不是原始术语 always:根据 suggestions 文字中的字词 suggest 任何相符的 suggestions 。

max_edits

最大编辑距离候选 suggestions 可以具有,以便被认为是 suggestion 。 只能是介于1和2之间的值。任何其他值都会导致抛出错误的请求错误。 默认为2。

prefix_length

必须匹配的最小前缀字符的数量是候选 suggestions 。 默认值为1.增加此数字可提高拼写检查性能。 通常拼写错误不会出现在术语的开头。 (旧名称“prefix_len”已弃用)

min_word_length

suggest 文本术语必须包含的最小长度。 默认值为4.(旧名称“min_word_len”已弃用)

max_inspections

用于乘以 shards_size 以便在碎片级别上检查更多候选拼写校正的因子。 可以以性能为代价提高精度。 默认为5。

min_doc_freq

suggestion 应该出现的文档数量的最小阈值。这可以指定为绝对数字或文档数量的相对百分比。 这可以通过仅提示高频项来提高质量。 默认值为0f,未启用。 如果指定的值大于1,则该数字不能为小数。 分片级文档频率用于此选项。

max_term_freq

suggestion 文本标记可以存在的文档数量中的最大阈值,以便包括。 可以是表示文档频率的相对百分比数字(例如0.4)或绝对数字。 如果指定的值大于1,则不能指定小数。 默认为0.01f。 这可以用于排除高频术语的拼写检查。 高频项通常拼写正确,这也提高了拼写检查的性能。 分片级文档频率用于此选项。

pre_filter

应用于传递到该候选生成器的每个令牌的过滤器(分析器)。 在生成候选项之前,此过滤器应用于原始令牌。

post_filter

在它们被传递给实际短语记分器之前应用于每个生成的令牌的过滤器(分析器)。

他下面的例子显示了一个短语 suggest 用两个生成器调用,第一个使用包含普通索引术语的字段,第二个使用使用索引与反向过滤器的术语的字段(令牌是相反顺序的索引)。 这用于克服直接发电机的限制,需要恒定的前缀来提供高性能 suggestions 。 pre_filter和post_filter选项接受普通分析器名称。

POST _suggest
{
  "text" : "obel prize",
  "simple_phrase" : {
    "phrase" : {
      "field" : "title.trigram",
      "size" : 1,
      "direct_generator" : [ {
        "field" : "title.trigram",
        "suggest_mode" : "always"
      }, {
        "field" : "title.reverse",
        "suggest_mode" : "always",
        "pre_filter" : "reverse",
        "post_filter" : "reverse"
      } ]
    }
  }
}

pre_filter和post_filter也可以用于在生成候选项之后注入同义词。 例如,对于查询caption usq,我们可以为项usq生成候选usa,这是 america的同义词,其允许如果该短语得分足够高则向用户呈现captain america。

suggesters