即使存在行,术语查询也会给出空行

问题描述 投票:0回答:1

我的弹性搜索中有这种类型的模式:

{
  "my_index": {
    "mappings": {
      "my_type": {
        "properties": {
          "mention_id": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "mentions": {
            "properties": {
              "name": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "score": {
                "type": "long"
              }
            }
          }
        }
      }
    }
  }
}

数据以这种格式存储:

{
"_index": "globalmentionkb",
"_type": "globalmentionkb",
"_id": "ylWDd2kBUYncqPcTEE3d",
"_version": 1,
"_score": 1,
"_source": {
"mention_id": "GBMEN-19379",
"mentions": [
{
"name": " Mohatma Ghandi",
"score": 1
}
,
{
"name": " Biography of Mahatma Gandhi",
"score": 1
}
,
{
"name": " Svadeshi",
"score": 1
}
,
{
"name": " Gandhy",
"score": 1
}
,
{
"name": " Gandhi's work in South Africa",
"score": 1
}
,
{
"name": " Mohandas Gandhi",
"score": 1
}
,
{
"name": " Mahondas Gandhi",
"score": 1
}
,
{
"name": " Mahatama Ghandi",
"score": 1
}
,
{
"name": " Mahatman Gandhi",
"score": 1
}
,
{
"name": " Bapu Gandhi",
"score": 1
}
,
{
"name": " Mohandas Ghandi",
"score": 1
}
,
{
"name": " Mahatma Karamchand Gandhi",
"score": 1
}
,
{
"name": " મોહનદાસ કરમચંદ ગાંધી",
"score": 1
}
,
{
"name": " Gandhi",
"score": 1
}
,
{
"name": " Ghondi",
"score": 1
}
,
{
"name": " Little brown saint",
"score": 1
}
,
{
"name": " Mohandas KaramChand Gandhi",
"score": 1
}
,
{
"name": " Barrister mohandas karamchand gandhi",
"score": 1
}
,
{
"name": " Father of India",
"score": 1
}
,
{
"name": " Matahama Gandhi",
"score": 1
}
,
{
"name": " Mahâtmâ Gandhi",
"score": 1
}
,
{
"name": " Gandhi poppadom",
"score": 1
}
,
{
"name": " The little brown saint",
"score": 1
}
,
{
"name": " M.K. Gandhi",
"score": 1
}
,
{
"name": " Mohandus Ghandi",
"score": 1
}
,
{
"name": " M.K.Gandhi",
"score": 1
}
,
{
"name": " Mahatama Gandhi",
"score": 1
}
,
{
"name": " Mohandas K. Gandhi",
"score": 1
}
,
{
"name": " Mahatma Mohandas Karamchand Gandhi",
"score": 1
}
,
{
"name": " Mahatma gandhi",
"score": 1
}
,
{
"name": " M K Gandhi",
"score": 1
}
,
{
"name": " Gahndi",
"score": 1
}
,
{
"name": " Mahatma Ghadhi",
"score": 1
}
,
{
"name": " Gandhiji",
"score": 1
}
,
{
"name": " Mohandas K Gandhi",
"score": 1
}
,
{
"name": " Africian raga",
"score": 1
}
,
{
"name": " Gandhi, Mohandas K.",
"score": 1
}
,
{
"name": " M. K. Gandhi",
"score": 1
}
,
{
"name": " M. K. Ghandi",
"score": 1
}
,
{
"name": " MK Gandhi",
"score": 1
}
,
{
"name": " Mahatma Gandhi bibliography",
"score": 1
}
,
{
"name": " Ghandi",
"score": 1
}
,
{
"name": " Gandi's work in south africa",
"score": 1
}
,
{
"name": " Mohandas Karamchand Gandhi in South Africa",
"score": 1
}
,
{
"name": " Gnadhi",
"score": 1
}
,
{
"name": " Gandhi, Mohandas Karamchand",
"score": 1
}
,
{
"name": " Mahatma Ghandhi",
"score": 1
}
,
{
"name": " Gandhian Movement",
"score": 1
}
,
{
"name": " Mahatma Ghandi",
"score": 1
}
,
{
"name": " Putlibai",
"score": 1
}
,
{
"name": " Saint of Sabarmati",
"score": 1
}
,
{
"name": " Mohandas Karamchand Gandhi",
"score": 1
}
,
{
"name": " Mohandas \Mahatma\ Gandhi",
"score": 1
}
]
}
}

现在我想只搜索那些提到名字“Gandhi”的实体。

{
  "query": {
    "term": {
      "mentions.name": "Gandhi" 
    }
  }
}

然后它给出null

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

即使我们有数据。你能告诉我怎么做才能从我的弹性搜索中得到确切的术语。

elasticsearch
1个回答
0
投票

看起来您使用标准分析器,默认情况下使用标记过滤器“小写”。

所以没有术语Gandhi,只有gandhi这个查询应该有效:

{
  "query": {
    "term": {
      "mentions.name": "gandhi" 
    }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.