使用@Query的Spring数据弹性搜索查询以错误的顺序返回结果

时间:2018-09-06 11:45:21

标签: spring elasticsearch

我在弹性搜索上使用了Followig查询:

 {"from":0,"size":10,"query":{"bool":{"must":{"bool":{"should":[{"term":{"fullName.keyword":{"value":"guide","boost":40.0,"_name":"exact match fullname"}}},{"term":{"firstName":{"value":"guide","boost":10.0,"_name":"exact match firstName"}}},{"term":{"lastName":{"value":"guide","boost":1.0,"_name":"exact match lastname"}}},{"query_string":{"fields":["firstName^2","lastName"],"query":"*guide*","_name":" analysed search match"}}]}},"must":{"match":{"orgId":1}},"should":[{"query_string":{"fields":["bossId"],"query":65849,"boost":4,"_name":"who reports me"}}],"should":[{"query_string":{"fields":["id"],"query":65840,"boost":2,"_name":"whom I reports"}}]}}}

我附上邮递员的回复

{
    "took": 8,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
    },
    "hits": {
        "total": 1657,
        "max_score": 299.31967,
        "hits": [
            {
                "_index": "globalsearch",
                "_type": "Guide",
                "_id": "67596",
                "_score": 299.31967,
                "_source": {
                    "dtype": "Guide",
                    "id": 67596,
                    "orgId": 1,
                    "title": "guide",
                    "description": "guide",
                    "visibleAll": false,
                    "aclUserIds": [
                        1,
                        65567,
                        65587,
                        2,
                        65753,
                        65644,
                        65737,
                        1,
                        2
                    ],
                    "author": 65587
                }
            },
            {
                "_index": "globalsearch",
                "_type": "Guide",
                "_id": "66923",
                "_score": 245.67525,
                "_source": {
                    "dtype": "Guide",
                    "id": 66923,
                    "orgId": 1,
                    "title": "guide",
                    "description": "desc",
                    "visibleAll": false,
                    "author": 65751
                }
            },
            {
                "_index": "globalsearch",
                "_type": "Guide",
                "_id": "66701",
                "_score": 223.21326,
                "_source": {
                    "dtype": "Guide",
                    "id": 66701,
                    "orgId": 1,
                    "title": "guide",
                    "description": "yttu",
                    "visibleAll": false,
                    "aclUserIds": [
                        1,
                        65594,
                        65567,
                        65587,
                        65583,
                        65591,
                        2,
                        65582,
                        65753,
                        65644,
                        65762,
                        65684,
                        65737,
                        65751,
                        1,
                        2
                    ],
                    "author": 65751
                }
            },

以及SpringData elasticsearch的响应。

[
  {
    "dtype": "Guide",
    "id": 67596,
    "dtype": "Guide",
    "orgId": 1,
    "title": "guide",
    "description": "guide",
    "visibleAll": false,
    "aclUserIds": [
      1,
      65567,
      65587,
      2,
      65753,
      65644,
      65737,
      1,
      2
    ],
    "author": 65587
  },
  {
    "dtype": "Guide",
    "id": 66806,
    "dtype": "Guide",
    "orgId": 1,
    "title": "guide",
    "description": "hjhj",
    "visibleAll": false,
    "aclUserIds": [
      65870,
      1,
      65594,
      65567,
      65587,
      2,
      65753,
      65644,
      65737,
      1,
      2
    ],
    "author": 65870
  },
  {
    "dtype": "Guide",
    "id": 66677,
    "dtype": "Guide",
    "orgId": 1,
    "title": "guide",
    "visibleAll": false,
    "aclUserIds": [
      1,
      65567,
      65587,
      65662,
      65681,
      2,
      65753,
      65755,
      65644,
      65737,
      1,
      2
    ],
    "author": 65755
  },

我无法找出这两个结果在排序上为何不同的原因。

0 个答案:

没有答案