21

我的映射定义中有以下字段:

...
"my_field": {
  "type": "string",
  "index":"not_analyzed"
}
...

当我索引具有该值的文档时,my_field = 'test-some-another'该值被拆分为 3 个术语:test, some, another.

我究竟做错了什么?

我创建了以下索引:

curl -XPUT localhost:9200/my_index -d '{
   "index": {
    "settings": {
      "number_of_shards": 5,
      "number_of_replicas": 2
    },
    "mappings": {
      "my_type": {
        "_all": {
          "enabled": false
        },
        "_source": {
          "compressed": true
        },
        "properties": {
          "my_field": {
            "type": "string",
            "index": "not_analyzed"
          }
        }
      }
    }
  }
}'

然后我索引以下文档:

curl -XPOST localhost:9200/my_index/my_type -d '{
  "my_field": "test-some-another"
}'

然后我将插件https://github.com/jprante/elasticsearch-index-termlist与以下 API 一起使用: curl -XGET localhost:9200/my_index/_termlist 这给了我以下响应:

{"ok":true,"_shards":{"total":5,"successful":5,"failed":0},"terms": ["test","some","another"]}

4

2 回答 2

23

通过运行验证映射是否实际设置:

curl localhost:9200/my_index/_mapping?pretty=true

创建索引的命令似乎不正确。它不应该包含"index" : {作为根元素。试试这个:

curl -XPUT localhost:9200/my_index -d '{
  "settings": {
    "number_of_shards": 5,
    "number_of_replicas": 2
  },
  "mappings": {
    "my_type": {
      "_all": {
        "enabled": false
      },
      "_source": {
        "compressed": true
      },
      "properties": {
        "my_field": {
          "type": "string",
          "index": "not_analyzed"
        }
      }
    }
  }
}'  
于 2012-05-14T13:34:28.033 回答
4

在 ElasticSearch 中,当字段进入倒排索引时,它就会被索引,lucene 使用这种数据结构来提供其强大而快速的全文搜索功能。如果要搜索某个字段,则必须对其进行索引。当你索引一个字段时,你可以决定是要按原样索引它,还是要分析它,这意味着决定一个标记器应用到它,这将生成一个标记列表(单词)和一个标记列表可以修改生成的令牌(甚至添加或删除一些)的过滤器。索引字段的方式会影响您对其进行搜索的方式。如果您索引一个字段但不对其进行分析,并且其文本由多个单词组成,您将能够找到该文档仅搜索该确切的特定文本,包括空格。

You can have fields that you only want to search on, and never show: indexed and not stored (default in lucene). You can have fields that you want to search on and also retrieve: indexed and stored. You can have fields that you don't want to search on, but you do want to retrieve to show them.

于 2015-08-22T10:50:26.377 回答