Elasticsearch:用語と一致の違い



Elasticsearch Difference Between Term



Elasticsearchの用語と一致の違い

用語は正確なクエリです



一致はあいまいなクエリです

用語クエリ



この用語は完全一致、つまり完全一致です。検索語は検索前にセグメント化されないため、検索語はドキュメントセグメンテーションセットの1つである必要があります。北京オリンピックというタイトルのすべてのドキュメントを検索するとします。

$curl -XGET http://localhost:9200/index/doc/_search?pretty -d '{ 'query':{ 'term':{ 'title': 'Beijing Olympics' } } }'


次の結果が得られます

{ 'took': 1, 'timed_out': false, '_shards': { 'total': 5, 'successful': 5, 'failed': 0 }, 'hits': { 'total': 1, 'max_score': 0.92055845, 'hits': [ { '_index': 'index', '_type': 'doc', '_id': '3', '_score': 0.92055845, '_source': { 'content': 'The same dream of the same world', 'title': 'Beijing Olympics', 'tags': [ 'peace' ] } } ] } }


一致クラスクエリ



一致クエリは、最初に検索語を分類します。単語のセグメンテーションの後、単語のセグメンテーションの結果は1つずつ照合されます。したがって、用語の正確な検索と比較すると、一致は分詞一致検索であり、一致検索には同様の機能の2つのバリアントがあります。 1つはmatch_phraseです。 1つはmulti_matchです。詳しく見てみましょう

一致

上記のように、一致検索は最初に検索語を分類します。最も基本的な一致検索の場合、検索ワードの単語セグメンテーションセットがドキュメント内に存在する限り、たとえば、中国の杭州を検索する場合、単語の最初の単語は中国語と杭州になります。 。文書に検索と杭州の単語が含まれている限り、検索されます。

$curl -XGET http://localhost:9200/index/doc/_search?pretty -d '{ 'query': { 'match': { 'content': 'Hangzhou, China' } } }'


ドキュメント3の本文には杭州があり、ドキュメント2には中国があるため、2つの検索結果があります。文書3では、杭州が2回出現しているため、1位にランクされています。結果は次のとおりです。

{ 'took' : 1, 'timed_out' : false, '_shards' : { 'total' : 5, 'successful' : 5, 'failed' : 0 }, 'hits' : { 'total' : 2, 'max_score' : 0.99999994, 'hits' : [ { '_index' : 'index', '_type' : 'doc', '_id' : '4', '_score' : 0.99999994, '_source' : { 'content' : 'Hangzhou is a beautiful city, welcome to Hangzhou', 'title' : 'propaganda', 'tags' : [ 'tourism', 'city'] } }, { '_index' : 'index', '_type' : 'doc', '_id' : '2', '_score' : 0.8838835, '_source' : { 'content' : 'China is the most populous country in the world', 'title' : 'China', 'tags' : [ 'China', 'population'] } } ] } }

元の参照: https://blog.csdn.net/sxf_123456/article/details/78845437