为什么 elasticsearch returns 对不同索引的相同查询的结果差异太大?
Why elasticsearch returns too different results for the same query on different indices?
我第一次使用 Elasticsearch 和 Kibana,所以请冷静对待我的问题!
我得到了一个 ES,它已经有一个名为 dai-*
的索引,其中预摄取了一些数据。为了安全地使用 ES,我创建了一个名为 ad-prior
的新索引。然后我继续为两个指数提供数据,如下所示:
{'obj_id': 'UHDRXEWEEK', 'event_type': 'PREC_AD_STARTED', 'event_id': '5c6b584373d', 'timestamp': 1550540223736L, 'channel_id': '123456789'}
{'obj_id': 'FDREJJSSHE', 'event_type': 'PREC_AD_STARTED', 'event_id': '4f53jhabd24', 'timestamp': 1550540225872L, 'channel_id': '123456789'}
然后我尝试在 Kibana 的 Discover 上进行搜索:
event_type.keyword:PREC_AD_STARTED
event_type:PREC_AD_STARTED
event_type:'PREC_AD_STARTED'
索引dai-*
:以上搜索所有returned 367 hits
.
索引 ad-prior
:以上搜索 returned 不同的结果:event_type:PREC_AD_STARTED
returning 8 hits
但另外两个 returning 0 hits
.
为什么上述搜索 return dai-*
的结果相同,而 return ad-prior
的结果不同?
更新
为了回答@Nishant Saini 的评论,我在此处抓取了 event_type
的我假设的映射:
对于dai-*
:
"event_type": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
对于ad-prior
:
"event_type": {
"type": "keyword",
"ignore_above": 1024
}
案例 1:event_type.keyword:PREC_AD_STARTED
在索引 dia-*
中,属性 event_type
有一个名为 keyword
的 sub-field。上面的查询引用了这个子字段,即 event_type.keyword
。对于 dai-*
中的匹配,返回文档,而索引 ad-prior
中的字段 event_type
不存在此子字段,因此没有结果。
案例二:event_type:PREC_AD_STARTED
event_type 出现在两个索引中。即使在索引 dai-*
中,数据类型是 text
,并且由于默认情况下应用标准分析器,因此 PREC_AD_STARTED
将导致 prec_ad_started
。上面的查询将相同的分析器应用于输入字符串,然后将其转换为 prec_ad_started
并因此与文档匹配。
在索引 ad-prior
的情况下, event_type
的数据类型是 keyword
因此输入字符串按原样索引。即使在搜索时也会发生同样的情况,因此上面的查询在这种情况下也匹配。
因此,此查询为您提供了两个索引的结果。
案例 3:event_type:'PREC_AD_STARTED'
对于索引 dai-*
因为查询是在字段 event_type
上(而不是在 event_type.keyword 上),当 [=21 时,它是 text
类型(默认分析器:标准) =] 被索引得到索引的值是 prec_ad_started
由于 standard analyzer。上面的查询正在搜索 'PREC_AD_STARTED'
(带单引号)。即使这个字符串也将通过标准分析器传递,它也转换为 prec_ad_started
因此这个查询匹配。
在ad-prior
索引的情况下,event_type
是类型keyword
,这意味着索引没有任何修改。由于我们在字段 event_type
上查询,查询将不应用任何分析器(因为数据类型是 keyword),因此将搜索 'PREC_AD_STARTED'
(不是 PREC_AD_STARTED
),因此没有匹配项.
我第一次使用 Elasticsearch 和 Kibana,所以请冷静对待我的问题!
我得到了一个 ES,它已经有一个名为 dai-*
的索引,其中预摄取了一些数据。为了安全地使用 ES,我创建了一个名为 ad-prior
的新索引。然后我继续为两个指数提供数据,如下所示:
{'obj_id': 'UHDRXEWEEK', 'event_type': 'PREC_AD_STARTED', 'event_id': '5c6b584373d', 'timestamp': 1550540223736L, 'channel_id': '123456789'}
{'obj_id': 'FDREJJSSHE', 'event_type': 'PREC_AD_STARTED', 'event_id': '4f53jhabd24', 'timestamp': 1550540225872L, 'channel_id': '123456789'}
然后我尝试在 Kibana 的 Discover 上进行搜索:
event_type.keyword:PREC_AD_STARTED
event_type:PREC_AD_STARTED
event_type:'PREC_AD_STARTED'
索引dai-*
:以上搜索所有returned 367 hits
.
索引 ad-prior
:以上搜索 returned 不同的结果:event_type:PREC_AD_STARTED
returning 8 hits
但另外两个 returning 0 hits
.
为什么上述搜索 return dai-*
的结果相同,而 return ad-prior
的结果不同?
更新
为了回答@Nishant Saini 的评论,我在此处抓取了 event_type
的我假设的映射:
对于dai-*
:
"event_type": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
对于ad-prior
:
"event_type": {
"type": "keyword",
"ignore_above": 1024
}
案例 1:event_type.keyword:PREC_AD_STARTED
在索引 dia-*
中,属性 event_type
有一个名为 keyword
的 sub-field。上面的查询引用了这个子字段,即 event_type.keyword
。对于 dai-*
中的匹配,返回文档,而索引 ad-prior
中的字段 event_type
不存在此子字段,因此没有结果。
案例二:event_type:PREC_AD_STARTED
event_type 出现在两个索引中。即使在索引 dai-*
中,数据类型是 text
,并且由于默认情况下应用标准分析器,因此 PREC_AD_STARTED
将导致 prec_ad_started
。上面的查询将相同的分析器应用于输入字符串,然后将其转换为 prec_ad_started
并因此与文档匹配。
在索引 ad-prior
的情况下, event_type
的数据类型是 keyword
因此输入字符串按原样索引。即使在搜索时也会发生同样的情况,因此上面的查询在这种情况下也匹配。
因此,此查询为您提供了两个索引的结果。
案例 3:event_type:'PREC_AD_STARTED'
对于索引 dai-*
因为查询是在字段 event_type
上(而不是在 event_type.keyword 上),当 [=21 时,它是 text
类型(默认分析器:标准) =] 被索引得到索引的值是 prec_ad_started
由于 standard analyzer。上面的查询正在搜索 'PREC_AD_STARTED'
(带单引号)。即使这个字符串也将通过标准分析器传递,它也转换为 prec_ad_started
因此这个查询匹配。
在ad-prior
索引的情况下,event_type
是类型keyword
,这意味着索引没有任何修改。由于我们在字段 event_type
上查询,查询将不应用任何分析器(因为数据类型是 keyword),因此将搜索 'PREC_AD_STARTED'
(不是 PREC_AD_STARTED
),因此没有匹配项.