我的弹性搜索中具有这种模式:
{
"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 :(得分:0)
好像您使用的是标准分析器,默认情况下使用令牌过滤器 “小写”。
因此没有术语Gandhi
,只有gandhi
此查询应该可以工作:
{
"query": {
"term": {
"mentions.name": "gandhi"
}
}
}