ElasticSearch:仅索引映射中指定的字段

问题描述:

我有一个ElasticSearch设置,接收要通过CouchDB河索引的数据。我遇到的问题是,CouchDB文档中的大多数字段实际上与搜索无关:它们是应用程序内部使用的字段(ID等),我不想因这些字段而误报。此外,索引不需要的数据在我看来是浪费资源。ElasticSearch:仅索引映射中指定的字段

为了解决这个问题,我已经定义了一个映射,我指定了我想要索引的字段。我正在使用pyes来访问ElasticSearch。我遵循的过程是:

  1. 创建与索引关联的CouchDB河流。这显然也创建了索引,并在该索引中创建了一个“couchdb”映射,就我所知,它包含了所有字段,并带有动态分配的类型。
  2. 把一个映射,restring它到我真正想索引的领域。

这是该指数定义为通过获得:

curl -XGET http://localhost:9200/notes_index/_mapping?pretty=true 

{ 
    "notes_index" : { 
    "default_mapping" : { 
     "properties" : { 
     "note_text" : { 
      "type" : "string" 
     } 
     } 
    }, 
    "couchdb" : { 
     "properties" : { 
     "_rev" : { 
      "type" : "string" 
     }, 
     "created_at_date" : { 
      "format" : "dateOptionalTime", 
      "type" : "date" 
     }, 
     "note_text" : { 
      "type" : "string" 
     }, 
     "organization_id" : { 
      "type" : "long" 
     }, 
     "user_id" : { 
      "type" : "long" 
     }, 
     "created_at_time" : { 
      "type" : "long" 
     } 
     } 
    } 
    } 
} 

,我的问题是许多倍:

  • 默认“CouchDB的”映射索引的所有字段。我不想要这个。是否有可能避免创建该映射?我很困惑,因为这种映射似乎是以某种方式“连接”到CouchDB河流的。
  • 我创建映射似乎没有任何效果:没有通过映射

索引你对此有何建议文件?

编辑

这就是我实际上做,输入号码:

server="localhost" 

# Create the index 
curl -XPUT "$server:9200/index1" 

# Create the mapping 
curl -XPUT "$server:9200/index1/mapping1/_mapping" -d ' 
{ 
    "type1" : { 
     "properties" : { 
      "note_text" : {"type" : "string", "store" : "no"} 
     } 
    } 
} 
' 

# Configure the river 
curl -XPUT "$server:9200/_river/river1/_meta" -d '{ 
    "type" : "couchdb", 
    "couchdb" : { 
     "host" : "localhost", 
     "port" : 5984, 
     "user" : "admin", 
     "password" : "admin", 
     "db" : "notes" 
    }, 
    "index" : { 
     "index" : "index1", 
     "type" : "type1" 
    } 
}' 

在索引1的文件还是超过“note_text”等领域,这是一个我在映射定义中特别提到。这是为什么?

CouchDB river的默认行为是使用'动态'映射,即索引传入CouchDB文档中找到的所有字段。你是对的,它可以不必要地增加索引的大小(你可以通过从查询中排除一些字段来解决你的搜索问题)。

,而不是使用的“动态”一个自己的映射,你需要配置河插件使用您所创建的映射(见this article):

curl -XPUT 'elasticsearch-host:9200/_river/notes_index/_meta' -d '{ 
    "type" : "couchdb", 

    ... your CouchDB connection configuration ... 

    "index" : { 
     "index" : "notes_index", 
     "type" : "mapping1" 
    } 
}' 

类型的名称您在映射中指定URL会覆盖您在定义中包含的那个,所以您创建的类型实际上是mapping1。尝试执行这个命令来查看自己:

> curl 'localhost:9200/index1/_mapping?pretty=true' 

{ 
    "index1" : { 
    "mapping1" : { 
     "properties" : { 
     "note_text" : { 
      "type" : "string" 
     } 
     } 
    } 
    } 
} 

我认为,如果你会得到正确类型的名称,它将开始正常工作。

+0

感谢您的评论,但有些事情尚不清楚。我在哪里使用我的映射(我称之为'default_mapping')在该PUT请求中? – dangonfast 2012-01-27 00:09:45

+0

您对每个索引有一个映射,但是您可以在每个映射中声明多个“类型”。我不确定你打算使用哪种映射类型 - 你有两个:'couchdb'和'default_mapping'。只需更改河流配置中“类型”键的值即可。 – 2012-01-27 00:24:01

+0

我编辑了原始问题,现在显示我正在配置ES的实际POST请求。这仍然不起作用:所有字段仍然被编入索引。 – dangonfast 2012-01-27 00:58:28