elasticsearch - Elasticsearch hits.total 与 OR 不同
问题描述
当我使用以下搜索(/posts/_search
)时,我的 hits.total 为 1400:
{"query": {"query_string": {"query": "Bitcoin"}}}
当我使用以下搜索(/posts/_search
)时,我的 hits.total 为 500:
{"query": {"query_string": {"query": "Ethereum"}}}
当我在搜索中使用 OR 时,它hits.total
是 1400,我预计它是 1900。
{"query": {"query_string": {"query": "(Ethereum) OR (Bitcoin)"}}}
当我使用“OR”时,为什么我的 hits.total 数字不同?我使用 hits.total 作为计数器来显示,数字应该是一样的,对吧?
我对 ElasticSearch 很陌生,希望有人能指出我正确的方向。谢谢!
解决方案
Most probably it Looks like there are some documents where **_all has both terms** i.e. Bitcoin and Ethereum, and hence, same documents get selected when u run the query independently, but when u run, this common documents get included only once.
May be this Venn diagram can explain better
A U B = (7+2+5) + (8+1+2+5) - (2+5) = 23
A + B = (7+2+5) + (8+1+2+5) = 30
If you are sure, these field which can never have multiple values then try adding "default_field" in the query and run the results. When you don't pass "default_field", if defaults to index.query.default_field index settings, which in turn defaults to _all.
{
"query": {
"query_string": {
"default_field": "CRYPTOCURRENCY_TYPE",
"query": "as"
}
}
}
More details you can be found here : https://www.elastic.co/guide/en/elasticsearch/reference/5.5/query-dsl-query-string-query.html
推荐阅读
- reactjs - 来自 React App 的 Google Maps Geocoding API 中的 CORS 错误
- python - 是否有一个函数可以为任何方向生成梯度?
- javascript - 如何防止 API 调用超时
- javascript - 刷新新打开的窗口后window.close()不起作用
- php - 数据库中的日期时间槽
- javascript - 如何将 crypto.WordArray 转换为 Uint8Array?
- javascript - React Material UI 构建问题
- javascript - 如何获取后端的当前基本 URL?
- javascript - 如何防止构造函数参数更改
- python - 将日期列一分为二