为什么索引false仍可搜索?

时间:2019-01-22 18:25:22

标签: elasticsearch

我对此感到困惑

我在弹性中定义了以下字段

  "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
                ]
            ]
        ]
    ]
];

1 个答案:

答案 0 :(得分:0)

这是一个Elasticsearch Internals主题。简而言之,该信息保留在_source中,由高亮显示。

更多细节。引用Mapping Parameters - index

  

索引选项控制是否对字段值建立索引。它接受truefalse,默认为true。未索引的字段不可查询。

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

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

Highlighting是另一个概念。

  

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

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

  • 更新文档(修复数据)
  • 为索引重新编制索引(固定数据)
  • 升级到较新的索引版本