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" } } }