在上一講咱們能夠發現,對於multi-value的搜索方式,實現起來能夠有多種方式。這裏就說明一下,實現的方式雖然不少,可是elasticsearch在查詢的時候底層都會轉換爲bool + term的形式java
{ "match": { "title": "java elasticsearch" } }
使用相似上面的match query進行多值搜索的時候,elasticsearch會在底層自動將這個match query轉換爲bool的語法elasticsearch
{ "bool": { "should": [ { "term": { "title": "java" } }, { "term: { "title": "elasticsearch" } } ] } }
{ "match": { "title": { "query": "java elasticsearch", "operator": "and" } } }
轉換爲:oop
{ "bool": { "must": [ { "term": { "title": "java" } }, { "term": { "title": "elasticsearch" } } ] } }
{ "match": { "title": { "query": "java elasticsearch spark hadoop", "minimum_should_match": 3 } } }
轉換爲:spa
{ "bool": { "should": [ { "term": { "title": "java" } }, { "term": { "title": "elasticsearch" } }, { "term": { "title": "spark" } }, { "term": { "title": "hadoop" } } ], "minimum_should_match": 3 } }