代码之家  ›  专栏  ›  技术社区  ›  Arayan Singh

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

  •  0
  • Arayan Singh  · 技术社区  · 5 年前

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

    {
      "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
    }
    ]
    }
    }
    

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

    那么它就给空了

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

    你能告诉我该怎么做才能从弹性搜索中得到准确的术语吗。

    0 回复  |  直到 5 年前
        1
  •  0
  •   Taras Kohut    5 年前

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

    Gandhi ,仅限 gandhi 此查询应适用于:

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