Elastic Search中的“标准”类型

我在具有以下结构的ElasticSearch中创建了索引

{
  "took": 17,"timed_out": false,"_shards": {
    "total": 1,"successful": 1,"skipped": 0,"failed": 0
  },"hits": {
    "total": {
      "value": 9,"relation": "eq"
    },"max_score": 1.0,"hits": [
      {
        "_index": "my_index2","_type": "_doc","_id": "ou57P24BbiLEFIdnhkkg","_score": 1.0,"_source": {
          "name": "Hung Le","age": "34"
        }
      },{
        "_index": "my_index2","_id": "o-57P24BbiLEFIdnx0kj","_source": {
          "name": "Viet Pham","age": "20"
        }
      },"_id": "pO58P24BbiLEFIdnAUm-","_source": {
          "name": "Quy Tran","age": "21"
        }
      },"_id": "pe58P24BbiLEFIdnJ0mn","_source": {
          "name": "Khiem Pham","age": "22"
        }
      },"_id": "pu58P24BbiLEFIdngUnX","_source": {
          "name": "PhamHoangViet","_id": "p-59P24BbiLEFIdnPUma","_source": {
          "name": "Nguyễn Trần Trung Quân","_id": "qO59P24BbiLEFIdnbkkO","_source": {
          "name": "Đặng Tấn Sĩ","_id": "qe5_P24BbiLEFIdnDknH","_source": {
          "name": "Văn Trung","_id": "qu5_P24BbiLEFIdnZkm3","_source": {
          "name": "Phạm Nguyễn Minh Quân","age": "34"
        }
      }
    ]
  }
}

这是我的数据:

http://localhost:9200/my_index2/_search?q=name:Trung+Quân

我用关键字“ TrungQuân”进行搜索:

{
  "took": 6,"hits": {
    "total": {
      "value": 3,"max_score": 2.19989,"_score": 2.19989,"_score": 1.497693,"_score": 1.099945,"age": "34"
        }
      }
    ]
  }
}

结果如下:

{
  "took": 9,"hits": {
    "total": {
      "value": 2,"max_score": 2.6052008,"_score": 2.6052008,"age": "21"
        }
      }

    ]
  }
}

它将检索包含单词“ Trung”或单词“Quân”的所有结果。现在,我必须如何配置索引,以便结果包含以下内容的“ Trung”和“Quân”:

from collections import Counter
import time
#10 sec
t_end = time.time() + 10
arr = []

while time.time() < t_end:
    #print(time.time())
    arr.append(random.randint(0,100))

arr = Counter(arr)
print(arr.most_common(3))
totomy 回答:Elastic Search中的“标准”类型

在您的示例中,name被映射为一个多字段,这意味着它在Elasticsearch中存储了两次:

  • 曾针对全文搜索(称为name)进行过一次优化,并且
  • 针对分析和完全匹配进行了一次优化(称为name.keyword

如果您只对精确匹配搜索感兴趣,而对不是全文搜索感兴趣,则可以通过“固定”映射来实现。只需将name映射为类型keyword的字段并重新索引您的文档即可。映射字段name

"name": {
    "type": "keyword"
}

如果要保留全文本搜索功能(在对name字段进行查询时),应保留映射不变,并尝试以下查询之一:

#1使用短语搜索的示例: (不需要完全匹配,但两个词都需要以正确的顺序/顺序匹配。请使用双引号)

http://localhost:9200/my_index2/_search?q=name:"Trung Quân"

#2使用完全匹配的示例: (姓名必须从头到尾匹配,且大小写和重音完全相同)

http://localhost:9200/my_index2/_search?q=name.keyword:"Trung Quân"
本文链接:https://www.f2er.com/3153292.html

大家都在问