elasticsearch - 如何从Elasticsearch中的嵌套数据类型查询中获取所有结果?

标签 elasticsearch nested lucene

我正在尝试使用Elasticsearch的嵌套数据类型从一滴文本中获取所有匹配的句子。在下面提到的查询中,我尝试过滤同一句子中提到的所有带有“the”和“of”的句子。

GET myindex/doc/_search
{
  "from": 0,
  "size": 1,
  "query": {
    "nested": {
      "path": "parent.data",
      "query": {
        "bool": {
          "filter": [
            {
              "match": {
                "parent.data.sentence": "the"
              }
            },
            {
              "match": {
                "parent.data.sentence": "of"
              }
            }
          ]
        }
      },
      "inner_hits": {}
    }
  }
}

尽管在下面添加的答复显示总共有544个文档,但是ES仅显示了其中三个。如何获得所有这些信息?
{
  "took": 709,
  "timed_out": false,
  "_shards": {
    "total": 6,
    "successful": 6,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 73783,
    "max_score": 0,
    "hits": [
      {
        "_index": "my-index",
        "_type": "doc",
        "_id": "bd9e3c03741956db68fd692a6914e811b0749baaf6565c6385380919f1ce3932",
        "_score": 0,
        "_source": {},
        "inner_hits": {
          "parent.data.sentence": {
            "hits": {
              "total": 544,
              "max_score": 0,
              "hits": [<response containing 3 sentence>],
          }
        }
      }
    ]
  }
}

最佳答案

您可以使用fromsize options获得所需的内部匹配数。默认情况下,内部匹配的size为3。要将其增加到20,您可以更新查询,如下所示:

GET myindex/doc/_search
{
  "from": 0,
  "size": 1,
  "query": {
    "nested": {
      "path": "parent.data",
      "query": {
        "bool": {
          "filter": [
            {
              "match": {
                "parent.data.sentence": "the"
              }
            },
            {
              "match": {
                "parent.data.sentence": "of"
              }
            }
          ]
        }
      },
      "inner_hits": {
        "size": 20
      }
    }
  }
}

如果不是要一次提取所有记录,我建议您使用fromsize的组合。

关于elasticsearch - 如何从Elasticsearch中的嵌套数据类型查询中获取所有结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56744648/

相关文章:

java - 嵌套在 do-while 循环中的 try-catch 没有实际循环是否有原因?

java - Lucene java,使用span查询查找每页的点击量

java - 在 Apache lucene 中导入 org.apache.lucene.analysis.SimpleAnalyzer 符号未找到错误

java - 卢塞恩 : Pagination returning duplicates

elasticsearch - ElasticSearch将1.x升级到6.x

elasticsearch - 如何在Elasticsearch中获取满足特定查询的所有不同字段值?

logging - 在 Elasticsearch docker 容器中找不到日志

elasticsearch - 如何过滤(排除)在Kibana中Elastic搜索查询DSL给出的所有结果?

json - 使用 jq 有条件地修改嵌套的 json

python - 根据多个条件创建列