假设索引的名称为索引且文档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"]
}
}
}
这将获得文档ID为“1”,但无法执行任何其他查询。
我要在单个文档中查询的原因是因为我的应用程序正在使用实时新闻 View
从服务器检索到新闻后,我想在elasticsearch中对其进行搜索,以查找关键提示和垃圾邮件过滤功能。
最佳答案
您必须使用Boolean Query组成查询
最好的方法是在过滤器下指定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"]}
}
]
}
}
}
关于elasticsearch - elasticsearch如何在单个文档中查询(搜索)?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60827014/