账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    GET查询,加.keyword与不加.keyword的区别是什么,为什么没有结果
    79
    0
    GET production-index-info/index_info/_search
    {
      "query": {
        "bool": {
          "minimum_should_match": 0,
          "must": [
            {
              "term": {
                "is_resolved.keyword": "解决"
              }
            }
          ],
          "should": []
        }
      }
    }

    使用这种方式查询,就可以得到数据。数据如下格式

    {
      "took": 51,
      "timed_out": false,
      "_shards": {
        "total": 5,
        "successful": 5,
        "skipped": 0,
        "failed": 0
      },
      "hits": {
        "total": 2914867,
        "max_score": 0.26003557,
        "hits": [
          {
            "_index": "production-index-info",
            "_type": "index_info",
            "_id": "5a5d4fcdc42fbc2bcefae14a",
            "_score": 0.26003557,
            "_source": {
              "created_time": "2020-01-21T22:44:50+08:00",
              "tickets": [],
              "is_resolved": "解决",
              "note": "",
            }
          },
          {
            "_index": "production-index-info",
            "_type": "index_info",
            "_id": "5a64a762cd1cb23dbb294bfa",
            "_score": 0.26003557,
            "_source": {
              "created_time": "2018-01-21T22:44:50+08:00",
              "tickets": [],
              "is_resolved": "解决",
              "note": "",
            }
          },
          {
            "_index": "production-index-info",
            "_type": "index_info",
            "_id": "5a5d88136817b27825831ac2",
            "_score": 0.26003557,
            "_source": {
              "created_time": "2018-01-16T13:05:23+08:00",
              "tickets": [],
              "is_resolved": "解决",
              "note": "11111",
            }
          },
          {
            "_index": "production-index-info",
            "_type": "index_info",
            "_id": "5a5dbc30c42fbc2ef1307ba9",
            "_score": 0.26003557,
            "_source": {
              "created_time": "2018-01-16T16:47:44+08:00",
              "tickets": [],
              "is_resolved": "未解决",
              "note": "222",
            }
          },
          ......
        ]
      }
    }

    但是如果使用这种方式,删除了.keywprd

    GET production-index-info/index_info/_search
    {
      "query": {
        "bool": {
          "minimum_should_match": 0,
          "must": [
            {
              "term": {
                "is_resolved": "解决"
              }
            }
          ],
          "should": []
        }
      }
    }

    那么结果就是这样的

    {
      "took": 0,
      "timed_out": false,
      "_shards": {
        "total": 5,
        "successful": 5,
        "skipped": 0,
        "failed": 0
      },
      "hits": {
        "total": 0,
        "max_score": null,
        "hits": []
      }
    }

    我知道这个.keyword和分词有关,但是对于这个例子,没有搞懂为什么,加了.keyword才可以查询出来结果,不加就不行了。另外,is_resolved的值,只有解决和未解决两个。

    4
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 叶筱引 普通会员 1楼

      在GET查询中,关键词"keyword"和不加关键词的区别主要体现在查询结果中是否包含"keyword"。

      如果在查询字符串中直接添加"keyword",那么查询结果中就会包含这个关键词。例如:

      http://example.com/?keyword=keyword

      如果查询字符串中不添加"keyword",那么查询结果中就不会包含这个关键词。例如:

      http://example.com/?keyword

      如果在查询字符串中直接添加"keyword",但没有在URL后面添加"/keyword",那么这个URL在浏览器中就无法解析为GET请求,因此这个URL在服务器端无法被处理,因此查询结果中就不会包含"keyword"。

      这就是为什么在GET查询中,加关键字与不加关键字的区别。

    更多回答
    扫一扫访问手机版