【问题标题】:why is index false still searchable?为什么 index false 仍然可以搜索?
【发布时间】:2019-01-23 18:41:55
【问题描述】:

我对此感到困惑

我在 elastic 中定义了以下字段

  "Email": {
    "type": "text",
    "boost": 0,
    "index": false,
    "analyzer": "standard"
  }

但是,当我搜索记录时,我得到的记录仅在该字段上匹配,并包含以下突出显示语句

  "highlight": {
    "properties.Email": [
      "<mark>someone</mark>@somewhere.com"
    ]
  }

我的理解是 index:false 应该阻止该字段被搜索,如果它不可搜索,则不应包含在突出显示的结果中

是我的理解错了还是有什么不对的地方

编辑:需要更多信息 需要完整的映射 原始数据是 GeoJson

 "index_5b17968c789cdb21dea23bfa": {
    "mappings": {
      "client_record": {
        "properties": {
          "geometry": {
            "type": "geo_shape"
          },
          "job_id": {
            "type": "keyword",
            "boost": 0,
            "index": false
          },
          "properties": {
            "properties": {
              "Address": {
                "type": "keyword",
                "boost": 0,
                "index": false
              },
              "Address_1": {
                "type": "text",
                "boost": 0,
                "index": false,
                "analyzer": "standard"
              },
              "Address_2": {
                "type": "keyword",
                "boost": 0,
                "index": false
              },
              "Address_3": {
                "type": "text",
                "boost": 0,
                "index": false,
                "analyzer": "standard"
              },
              "Company": {
                "type": "keyword",
                "boost": 18
              },
              "County": {
                "type": "text",
                "boost": 0,
                "index": false,
                "analyzer": "standard"
              },
              "Email": {
                "type": "text",
                "boost": 0,
                "index": false,
                "analyzer": "standard"
              },
              "Ref_ID": {
                "type": "keyword",
                "boost": 27
              },
              "FirstName": {
                "type": "text",
                "boost": 0,
                "index": false,
                "analyzer": "standard"
              },
              "Job_Title": {
                "type": "keyword",
                "boost": 0,
                "index": false
              },
              "Land_Description": {
                "type": "keyword",
                "boost": 0,
                "index": false
              },
              "Registry_Title": {
                "type": "keyword",
                "boost": 18
              },
              "LastName": {
                "type": "keyword",
                "boost": 0,
                "index": false
              },
              "Middlename": {
                "type": "keyword",
                "boost": 0,
                "index": false
              },
              "Mobile": {
                "type": "keyword",
                "boost": 0,
                "index": false
              },
              "Name": {
                "type": "keyword",
                "boost": 18
              },
              "Notes": {
                "type": "keyword",
                "boost": 0,
                "index": false
              },
              "Record_Type": {
                "type": "keyword",
                "boost": 0,
                "index": false
              },
              "Parish_Council": {
                "type": "keyword",
                "boost": 0,
                "index": false
              },
              "Item_Name": {
                "type": "keyword",
                "boost": 0,
                "index": false
              },
              "Postcode": {
                "type": "keyword",
                "boost": 0,
                "index": false
              },
              "Preferred_Contact_Method": {
                "type": "keyword",
                "boost": 0,
                "index": false
              },
              "Prior_Notification": {
                "type": "keyword",
                "boost": 0,
                "index": false
              },
              "Tel": {
                "type": "keyword",
                "boost": 0,
                "index": false
              },
              "Tenure": {
                "type": "keyword",
                "boost": 0,
                "index": false
              },
              "Title": {
                "type": "keyword",
                "boost": 0,
                "index": false
              },
              "Town": {
                "type": "keyword",
                "boost": 0,
                "index": false
              },
              "Work_Tel": {
                "type": "keyword",
                "boost": 0,
                "index": false
              }
            }
          },
          "type": {
            "type": "keyword",
            "boost": 0,
            "index": false
          }
        }
      }
    }
  }
}

请求了搜索逻辑,因此在此处添加它

我使用的是 PHP 界面,但这是搜索查询

在哪里 $q 是用户提供的字符串 $index 是被搜索的索引

[
    'index' => $index ,
    'ignore_unavailable'=>true,
    'size' => 20,
    'body' => [
        'query' => [
            'bool' => [
                'must' => [
                    "bool" => [
                        "should" => [
                            [
                                "match_phrase" => [
                                    "_all" => [
                                        "query" => $q,
                                        "boost" => 8
                                    ]
                                ]
                            ],
                            [
                                "match" => [
                                    "_all" => [
                                        "query" => $q,
                                        "operator"=> "and",
                                        "boost" => 2
                                    ]
                                ]
                            ],
                            [
                                "match" => [
                                    "_all" => [
                                        "query" => $q,
                                        "boost" => 1
                                    ]
                                ]
                            ],
                            [
                                "wildcard" => [
                                    "_all" => [
                                        "wildcard" => '*' . $q . '*',
                                        "boost" => 0.5
                                    ]
                                ]
                            ]
                        ]
                    ]

                ]
            ]
        ],
        'highlight' => [
            'pre_tags' => ['<mark>'],
            'post_tags' => ['</mark>'],
            'fields' => [
                '*' => [
                    'require_field_match' => false
                ]
            ]
        ]
    ]
];

【问题讨论】:

  • "index": false 应该阻止 Elastic 索引该字段。你的映射的其余部分是什么样的?突出显示后您的查询是什么样的?
  • 您能否发布您的搜索查询,看看您尝试了什么?
  • @Tim 添加了其余的映射
  • @cinhtau 添加了,现在我觉得自己完全是个白痴,因为我忘记了在突出显示中添加了 'require_field_match' => false,这是我更改默认行为的答案,这就是为什么它没有遵循默认行为

标签: elasticsearch


【解决方案1】:

这是一个 Elasticsearch 内部主题。简而言之,信息保留在_source 中,因为它被高亮使用。

更详细一点。引用Mapping Parameters - index

索引选项控制字段值是否被索引。它接受truefalse 并默认为true。未编入索引的字段不可查询。

这就是全部。该值不会进入 Apache Lucene 的inverted index,因此查询毫无意义。但是,该字段仍保留在 _source 中,并且仍可用于聚合。聚合示例:假设您想知道特定邮件地址存在多少文档。

如果您不想将其用于聚合,可以添加"enabled": false mapping parameter

Highlighting 是另一个概念。

如果不存储该字段(映射未将store设置为true),则加载实际的_source,并从_source中提取相关字段。

简而言之,它访问_source 字段。映射参数indexenabled 的信息保留在_source 中。在大多数情况下,这是强制性的。如果禁用源,则不能

  • 更新文档(修复数据)
  • 重新索引索引(修复数据)
  • 升级到更新的索引版本

【讨论】:

  • 所以你是说突出显示是一个红鲱鱼,突出显示的不是用于在搜索中匹配此记录的索引区域?
  • @MikeT 我不熟悉红鲱鱼这个词,但我想关键是要区分搜索和突出显示字段值。我认为弹性可以改进文档。在 Elastic Engineer Training 中,您将了解 Elasticsearch Internals。 HTH
  • 红鲱鱼是一种误导或分散相关或重要问题的东西
猜你喜欢
  • 2019-12-31
  • 1970-01-01
  • 1970-01-01
  • 2021-01-01
  • 2020-08-02
  • 2019-07-09
  • 2017-07-08
  • 2019-06-12
  • 2021-07-24
相关资源
最近更新 更多