Термин запроса дает пустые строки, даже если строка присутствует - PullRequest
0 голосов
/ 14 марта 2019

В моем упругом поиске есть схема такого типа:

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

даже если у нас есть данные. Можете ли вы сказать мне, что я должен сделать, чтобы получить точный термин из моего упругого поиска.

1 Ответ

0 голосов
/ 14 марта 2019

Похоже, вы используете стандартный анализатор, который по умолчанию использует маркерный фильтр "строчные буквы".

Таким образом, нет термина Gandhi, только gandhi Этот запрос должен работать:

{
  "query": {
    "term": {
      "mentions.name": "gandhi" 
    }
  }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...