PUT s1/_doc/1 { "title": "中國是世界人口最多的國家" } PUT s1/_doc/2 { "title": "美國是世界上軍事最強的國家" } PUT s1/_doc/3 { "title": "日本是世界上漁業最豐富的國家" } GET s1/_search { "query": { "match": { "title": "中國" } } } GET s1/_search { "query": { "match_phrase": { "title": "中國" } } } GET s1/_search { "query": { "match_phrase": { "title": { "query": "中國人口", "slop": 5 } } } } # 最左前綴查詢 PUT s2/_doc/1 { "title": "beautiful girl" } PUT s2/_doc/2 { "title": "beautiful so" } GET s2/_search { "query": { "match_phrase_prefix": { "title": "b" } } } PUT s2/_doc/3 { "t1": "xiong beautiful boy", "t2": "qiu beautiful" } # 指定查詢的字段,自動分詞 GET s2/_search { "query": { "multi_match": { "query": "beautiful boy", "fields": ["title"] } } } # 指定查詢的字段,短句,不分詞 GET s2/_search { "query": { "multi_match": { "query": "xiong", "fields": ["t1", "t2", "title"], "type": "phrase" } } } # 指定查詢的字段,短句,最左前綴原則 GET s2/_search { "query": { "multi_match": { "query": "be", "fields": ["t1", "t1", "title"], "type": "phrase_prefix" } } } GET s2/_search { "query": { "multi_match": { "query": "be", "fields": ["t1", "t1", "title"], "type": "phrase" } } }