如何修改nutch索引编写器用于elasticsearch的索引模板?

时间:2015-12-03 12:16:23

标签: templates elasticsearch nutch mappings indexwriter

弹出搜索的nutch索引编写器在弹性搜索中生成一个索引,其名称在属性元素中的nutch-site.xml(或nutch-default.xml)中提供:

   <property> 
     <name>elastic.index</name>
     <value>nutch</value> 
     <description>Default index to send documents to.</description>
   </property>

此类自动生成索引的elasticsearch中的映射部分始终具有以下结构

   {
       "nutch": {
           "mappings": {
               "doc": {
                   "properties": {
                       "anchor": {
                           "type": "string"
                       },
                       "boost": {
                           "type": "string"
                       },
                       "cache": {
                           "type": "string"
                       },
                       "content": {
                           "type": "string"
                       },
                       "contentLength": {
                           "type": "string"
                       },
                       "date": {
                           "type": "date",
                           "format": "dateOptionalTime"
                       },
                       "digest": {
                           "type": "string"
                       },
                       "host": {
                           "type": "string"
                       },
                       "id": {
                           "type": "string"
                       },
                       "lang": {
                           "type": "string"
                       },
                       "lastModified": {
                           "type": "date",
                           "format": "dateOptionalTime"
                       },
                       "segment": {
                           "type": "string"
                       },
                       "title": {
                           "type": "string"
                       },
                       "tstamp": {
                           "type": "date",
                           "format": "dateOptionalTime"
                       },
                       "type": {
                           "type": "string"
                       },
                       "url": {
                           "type": "string"
                       }
                   }
               }
           }
       }
   }
  1. 这个模板在哪里?
  2. 可以改变吗?
  3. 如果是,哪些字段是必填字段,哪些是可选字段?
  4. 我在哪里可以找到更多相关信息?
  5. 任何帮助表示赞赏! 谢谢,Wolfram

1 个答案:

答案 0 :(得分:2)

欢迎使用StackOverflow !!

以下是我对你问题的看法:

  1. 看起来Nutch没有创建任何模板。以下是ElasticIndexWriter的源代码,您可以看到任何地方都没有对任何模板的引用。

  2. 由于Nutch没有创建任何索引模板,因此您无法对其进行更改...但如果您需要/需要控制,您可以直接在ES群集中​​创建一个某些领域的映射。

  3. 您可以开始使用Nutch创建的默认映射(即您在问题中粘贴的映射)并对其进行迭代。从中创建模板是微不足道的,即您只需添加"template": "nutch*"属性(下面的第一行),您就可以继续(有关如何更改映射的更多信息available here) :

    curl -XPUT localhost:9200/_template/nutch_template -d '{
      "template": "nutch*",
      "mappings": {
        "doc": {
          "properties": {
            "anchor": {
              "type": "string"
            },
            "boost": {
              "type": "string"
            },
            "cache": {
              "type": "string"
            },
            "content": {
              "type": "string"
            },
            "contentLength": {
              "type": "string"
            },
            "date": {
              "type": "date",
              "format": "dateOptionalTime"
            },
            "digest": {
              "type": "string"
            },
            "host": {
              "type": "string"
            },
            "id": {
              "type": "string"
            },
            "lang": {
              "type": "string"
            },
            "lastModified": {
              "type": "date",
              "format": "dateOptionalTime"
            },
            "segment": {
              "type": "string"
            },
            "title": {
              "type": "string"
            },
            "tstamp": {
              "type": "date",
              "format": "dateOptionalTime"
            },
            "type": {
              "type": "string"
            },
            "url": {
              "type": "string"
            }
          }
        }
      }
    }'
    

    3-4。 Nutch in their wiki索引/存储了所有字段的描述,因此您可以修改上面的映射,以便以不同方式存储/索引某些字段以符合您的确切需求。

    注意:请务必首先擦除当前的nutch索引,然后创建模板(上面的第2点),然后当Nutch将索引其第一个文档时,将自动创建索引。

    您可能也有兴趣调查问题FLUME-2787,因为其他人似乎已经完成了模板创建。你可能会在那里找到一些金块。