【问题标题】:can I limit number of indexing fields in elasticsearch 5.3我可以限制弹性搜索 5.3 中的索引字段数量吗
【发布时间】:2017-04-12 05:31:33
【问题描述】:

Elasticsearch 新手。我看到默认情况下,ES 为每个字段中的每个单词创建索引。但在我的用例中,我将只搜索两个字段,所以我想以某种方式告诉 ES 不要为文档中的所有内容创建索引,而是只为我在映射中指定的字段创建索引。

这是我的映射

PUT /benefits
  { 
     "mappings": {
       "benefit": {
         "_all": {"enabled": false},
          "properties": {
            "subCategory": {"type": "text"},
            "description": {"type": "text"}
         }  

       }
   }
}

我的文档看起来像这样

{
"bpi" : "123456",
"category" : "CAT1",
"subCategory" : "Primary Care Physician Copay",
"planName" : "MyPlan HMO Individual",
"description" : "0 per office visit for Convenient Care & Minute Clinics Complete ABC Document",
"categoryId" : 200.0,
"desktop360Id" : 1001.0,
"createTimeStamp" : "2017-02-21T22:00:12.000Z"

}

所以我将只搜索 "subCategory""description"(而不是 "planName" 或任何其他字段文本)并创建索引/映射,如上面的映射所示,但我仍然能够搜索文本其他领域也是如此。例如,如果我从 "planName" 字段中搜索“MyPlan”,则搜索工作并显示此文档。这是否意味着它为所有字段上的所有单词(除了那些'a','of'类型)创建了索引?我问这个问题是因为,我不想把内存花在我不需要的索引上。

有什么建议吗?

【问题讨论】:

  • 您只需将"dynamic": "false" 添加到您的映射中(与“_all”相同的级别)。这将在对象级别执行此操作,但您也可以在索引级别或模板中设置它以为所有索引设置它。有关此可用的信息here
  • 谢谢奥利维尔。我想我明白了。请参阅我在“回答您的问题”中添加的示例

标签: elasticsearch elasticsearch-5


【解决方案1】:

为了从索引中排除其他字段,您必须在映射中指定它们并将index 属性设置为no 值。这是一个例子

{
    "mappings": {
        "benefit": {
            "properties": {
                "subCategory": {
                    "type": "string"
                },
                "description": {
                    "type": "string"
                },
                "planName": {
                    "type": "string",
                    "index": "no"
                },
                "bpi": {
                    "type": "string",
                    "index": "no"
                },
                "category": {
                    "type": "string",
                    "index": "no"
                }
            }
        }
    }
}

【讨论】:

  • 我有一个后续问题。我知道我应该发布一个不同的问题,但我已经在这里输入了问题的上下文,让我问你这个问题。如何在“子类别”中找到的搜索结果超过“描述”的权重?有什么建议吗?
  • 我通过在创建索引时向这两个字段添加“提升”值来计算这一点。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多