elasticsearch - elasticsearch 如何在单个文档中查询(搜索)?
问题描述
假设索引的名称是索引 & 文档 1 的 id 是“1”
如何在单个文档中查询?
像这样的东西..
GET index/_search
{
"query": {
"id": "1",
"terms": ["is this text in document 1?"]
}
}
或者
GET index/_doc/1/_search
{
...
}
据我发现,
GET test/_doc/_search
{
"query": {
"terms" : {
"_id" : ["1"]
}
}
}
这将获得“1”的文档 ID,但无法执行任何进一步的查询。
我想在单个文档中查询的原因是因为我的应用程序正在使用实时新闻视图,并且一旦从服务器检索到新闻,我想在弹性搜索中搜索它以查找关键工作突出显示和垃圾邮件过滤。
解决方案
您必须使用布尔查询来编写查询
最好的方法是在过滤器下指定 id 查询,因为它不会影响评分。接下来,您可以根据需要在 must、must_not 和 should 下指定查询:
GET index/_search
{
"from": 0,
"size": 10,
"query": {
"bool": {
"must": [
{
"term": {
"field": "value"
}
}
],
"must_not": [],
"should": [],
"filter": [
{
"terms": {"_id": ["1"]}
}
]
}
}
}
推荐阅读
- php - 在 WHILE LOOP 内更新查询:为 Bisi 虚拟牛群增加权重
- c# - 如何在 C# 中停止复制 rdlc 报告中的行
- php - 在 PHP 中使用数组作为请求标头
- r - How can I find the most common sequences in my data using R?
- google-docs-api - 如何从 Google Docs API 的文档中获取页面的 startIndex 和 endIndex?
- python - 我们如何对使用 google-ads 编写的应用程序进行集成测试?
- python - 如何选择价值?
- c# - 如何使用带有主应用程序的 OpenTelemetry 在任何数据库中保存行跟踪数据
- sql - Oracle SQL根据其他列的值添加新列
- c# - 如何使用 C# 中的指针安全地清除 TextBox 的内容?