【发布时间】: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