ElasticSearch - 按内部点击

时间:2018-02-19 10:15:57

标签: elasticsearch elasticsearch-5

我们有一个带映射的实体的简单索引:

PUT resource/_mapping/entity
{
  "properties": {
    "id": {
      "type": "keyword"
    },
    "name": {
      "type": "keyword"
    },
    "claims": {
      "type": "nested",
      "properties": {
        "claimid": {
          "type": "keyword"
        },
        "priority": {
          "type": "short"
        },
        "visibility": {
          "type": "keyword"
        }
      }
    }
  }
}

以下是索引中的示例文档:

POST resource/entity/
{
  "id": "2",
  "name": "e2",
  "claims": [
    {
      "claimid": "c1",
      "priority": "2",
      "visibility": "M",
      "reqid" : "2"
    },
    {
      "claimid": "c2",
      "priority": "1",
      "visibility": "V",
      "reqid" : "2"
    },
    {
      "claimid": "c5",
      "priority": "3",
      "visibility": "H",
      "reqid" : "2"
    }
  ]
}

通过提供的'claims.claimid'集合来过滤文档的查询,然后按'claims.priority'排序,选择具有最高优先级的文件并仅返回'claims.visibility',例如:

GET resource/entity/_search/
{
  "query": {
    "nested": {
      "path": "claims",
      "query": {
        "bool": {
          "must": [
            {
              "terms": {
                "claims.claimid": [
                  "c1",
                  "c4",
                  "c5"
                ]
              }
            }
          ]
        }
      },          
      "inner_hits": {
        "sort": [
          {
            "claims.priority": "asc"
          }
        ],
        "size":1,
        "_source":{"includes":["claims.visibility"]}
      }
    }
  }
}

最后要解决的问题是:如何修改查询以过滤掉导致“H”的文档,以获得内部命中率最高的可见性?或者其他什么查询将返回一组文档,其中包含所提供的声明ID筛选的具有最高优先级的可见性,但只有那些可见性不是“H”的文档?

这里的一个问题是,我们必须对具有所有类型可见性的文档进行排序,并在完整的结果列表中筛选出结果为“H”的文档。

0 个答案:

没有答案