index_options(索引设置)

index_options 参数用于控制添加到倒排索引中的信息,服务于搜索和高亮等目的。他可以包括以下参数:

docs: 只有文档编号被索引。能够回答的问题只有此 term(词条)是否存在于此字段。

freqs:文档编号和 term(词条)的频率会被索引。term(词条)频率用于给搜索评分,重复出现的 term(词条)评分将高于单个出现的 term(词条)。

positions:文档编号、term frequencies(词条频率)和 term(词条)位置(或顺序)将被索引。Position被用于 proximity queries (邻近查询)和 phrase queries(短语查询)。

offsets: 文档编号、term(词条)频率,位置,起始和结尾字符偏移量(用于映射该 term (词条)到原始字符串)将被索引。Offset用于postings highlighter

被分析器分析的字符串字段使用 position 作为默认值,其他的字段使用 docs 作为默认值。

  1. curl -XPUT 'localhost:9200/my_index?pretty' -H 'Content-Type: application/json' -d'
  2. {
  3. "mappings": {
  4. "my_type": {
  5. "properties": {
  6. "text": {
  7. "type": "text",
  8. "index_options": "offsets"
  9. }
  10. }
  11. }
  12. }
  13. }
  14. '
  15. curl -XPUT 'localhost:9200/my_index/my_type/1?pretty' -H 'Content-Type: application/json' -d'
  16. {
  17. "text": "Quick brown fox"
  18. }
  19. '
  20. curl -XGET 'localhost:9200/my_index/_search?pretty' -H 'Content-Type: application/json' -d'
  21. {
  22. "query": {
  23. "match": {
  24. "text": "brown fox"
  25. }
  26. },
  27. "highlight": {
  28. "fields": {
  29. "text": {} #1
  30. }
  31. }
  32. }
  33. '

| 1 | text 字段将使用postings highlighter 作为默认值,因为他的索引配置为 offsets。 |

原文链接 : https://www.elastic.co/guide/en/elasticsearch/reference/5.3/index-options.html(修改该链接为官网对应的链接)

译文链接 : http://www.apache.wiki/pages/viewpage.action?pageId=9405579(修改该链接为 ApacheCN 对应的译文链接)

贡献者 : 郭峰ApacheCNApache中文网