ElasticSearch检索结果,价值减半

xqnpmsa8  于 2022-11-22  发布在  ElasticSearch
关注(0)|答案(1)|浏览(121)

我试图检查client_id是否已经存在于索引中。但问题是ES仍然检索完整的ID,即使我给出了一半的ID。下面是Map。

'mappings': {
            'properties': {
                'client_id': {'index': 'true','type': 'keyword'},
                'client_name': {'index': 'true', 'type': 'keyword'},
                'data_index_server': {'type': 'ip'},
                'data_file_node_path': {'index': 'true', 'type': 'keyword'},
            }

如果我有这样的唱片

{
  "_index": "client_index",
  "_type": "_doc",
  "_id": "wYlkrYMB_q_jkYaCv6pU",
  "_version": 1,
  "_score": 1,
  "_source": {
    "doc": {
      "client_id": "0935be6b-61fe-4ec4-80c8-5c5ee8384378",
      "client_name": "citi",
      "data_file_node_path": " ",
      "data_index_server": " "
    }
  },
  "fields": {
    "doc.client_id": [
      "0935be6b-61fe-4ec4-80c8-5c5ee8384378"
    ],
    "doc.client_name": [
      "sample_name"
    ],
    "doc.data_index_server": [
      " "
    ],
    "doc.client_name.keyword": [
      "citi"
    ],
    "doc.data_file_node_path.keyword": [
      " "
    ],
    "doc.client_id.keyword": [
      "0935be6b-61fe-4ec4-80c8-5c5ee8384378"
    ],
    "doc.data_index_server.keyword": [
      " "
    ],
    "doc.data_file_node_path": [
      " "
    ]
  }
}

我对搜索的要求是这样的。如果我取ID的某个部分并对它进行搜索。我期望的是命中将是零

POST /client_index/_search

    {
      "query": {
          "match": {
              "doc.client_id":"0935be6b-61fe-4ec4-80c8" ,
          }
      }
    }

我有王莽这个网址:How to make elastic search only match full field。将字段类型更改为关键字,并在true和false之间切换索引,但没有结果

bfrts1fy

bfrts1fy1#

我认为您混淆了一些东西,在Map中,您只显示了四个属性,这些属性是简单的字段,而在搜索响应中,它在fields下有其他字段,这些字段的类型是object
您读对了,不分析keyword字段,并且在这些字段上,您将仅获得完整字段值的结果。
您应该尝试将client-id定义为带有示例字段的新索引中的关键字字段,然后在该索引上进行搜索以查看它的运行情况。

相关问题