search API (二) request uri方式查询 柔情只为你懂 2022-12-16 13:16 135阅读 0赞 ## search 查询需注意: ## ()表示分组,括号里的多种值应用于同一个字段,比如 name:(zhangsan lisi),查询name为zhangsan或者lisi的文档。 布尔查询 AND OR NOT需要大写。 单个词查询是 term查询。 多个词用引号表示是phrase查询。 ## 创建5条数据,用于测试 ## post goods/_doc/1 { "name":"apple A", "desc":"Beautiful Mind A", "createDate":2001 } post goods/_doc/2 { "name":"apple B", "desc":"Beautiful Mind B", "createDate":2010 } post goods/_doc/3 { "name":"orange A", "desc":"Beautiful A", "createDate":2009 } post goods/_doc/4 { "name":"orange B", "desc":"Mind A", "createDate":2009 } post goods/_doc/5 { "name":"fruit F", "desc":"F F F", "createDate":2009 } ## **查询测试:** ## ### 1 uri查询 ### \# q 查询条件,df 默认查询字段,sort 排序 \# from size 分页,timeout 超时时间 \# profile查看执行过程 get goods/\_search?q=A&df=name&sort=createDate:asc&from=0&size=10&timeout=1s \{ "profile":true \} { "took" : 1, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 2, "relation" : "eq" }, "max_score" : null, "hits" : [ { "_index" : "goods", "_type" : "_doc", "_id" : "1", "_score" : null, "_source" : { "name" : "apple A", "desc" : "Beautiful Mind A", "createDate" : 2001 }, "sort" : [ 2001 ] }, { "_index" : "goods", "_type" : "_doc", "_id" : "3", "_score" : null, "_source" : { "name" : "orange A", "desc" : "Beautiful A", "createDate" : 2009 }, "sort" : [ 2009 ] } ] }, "profile" : { "shards" : [ { "id" : "[GiqyrgdeRXmHsb5T6U1N4Q][goods][0]", "searches" : [ { "query" : [ { "type" : "TermQuery", "description" : "name:a", "time_in_nanos" : 64457, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 0, "shallow_advance_count" : 0, "set_min_competitive_score" : 0, "next_doc" : 811, "match" : 0, "next_doc_count" : 2, "score_count" : 0, "compute_max_score_count" : 0, "compute_max_score" : 0, "advance" : 1542, "advance_count" : 2, "score" : 0, "build_scorer_count" : 7, "create_weight" : 14532, "shallow_advance" : 0, "create_weight_count" : 1, "build_scorer" : 47560 } } ], "rewrite_time" : 2323, "collector" : [ { "name" : "CancellableCollector", "reason" : "search_cancelled", "time_in_nanos" : 41497, "children" : [ { "name" : "SimpleFieldCollector", "reason" : "search_top_hits", "time_in_nanos" : 35104 } ] } ] } ], "aggregations" : [ ] } ] } } ### 2 泛查询,在所有字段查询A ### get goods/\_search?q=A \{ "profile":true \} { "took" : 1, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 3, "relation" : "eq" }, "max_score" : 0.87546873, "hits" : [ { "_index" : "goods", "_type" : "_doc", "_id" : "1", "_score" : 0.87546873, "_source" : { "name" : "apple A", "desc" : "Beautiful Mind A", "createDate" : 2001 } }, { "_index" : "goods", "_type" : "_doc", "_id" : "3", "_score" : 0.87546873, "_source" : { "name" : "orange A", "desc" : "Beautiful A", "createDate" : 2009 } }, { "_index" : "goods", "_type" : "_doc", "_id" : "4", "_score" : 0.5951853, "_source" : { "name" : "orange B", "desc" : "Mind A", "createDate" : 2009 } } ] }, "profile" : { "shards" : [ { "id" : "[GiqyrgdeRXmHsb5T6U1N4Q][goods][0]", "searches" : [ { "query" : [ { "type" : "DisjunctionMaxQuery", "description" : """(desc.keyword:A | name:a | name.keyword:A | MatchNoDocsQuery("failed [createDate] query, caused by number_format_exception:[For input string: "A"]") | desc:a)""", "time_in_nanos" : 150715, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 0, "shallow_advance_count" : 0, "set_min_competitive_score" : 0, "next_doc" : 20848, "match" : 0, "next_doc_count" : 6, "score_count" : 3, "compute_max_score_count" : 0, "compute_max_score" : 0, "advance" : 0, "advance_count" : 0, "score" : 5030, "build_scorer_count" : 8, "create_weight" : 74700, "shallow_advance" : 0, "create_weight_count" : 1, "build_scorer" : 50119 }, "children" : [ { "type" : "TermQuery", "description" : "desc.keyword:A", "time_in_nanos" : 29218, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 0, "shallow_advance_count" : 0, "set_min_competitive_score" : 0, "next_doc" : 0, "match" : 0, "next_doc_count" : 0, "score_count" : 0, "compute_max_score_count" : 0, "compute_max_score" : 0, "advance" : 0, "advance_count" : 0, "score" : 0, "build_scorer_count" : 5, "create_weight" : 27501, "shallow_advance" : 0, "create_weight_count" : 1, "build_scorer" : 1711 } }, { "type" : "TermQuery", "description" : "name:a", "time_in_nanos" : 39177, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 0, "shallow_advance_count" : 4, "set_min_competitive_score" : 0, "next_doc" : 0, "match" : 0, "next_doc_count" : 0, "score_count" : 2, "compute_max_score_count" : 2, "compute_max_score" : 5857, "advance" : 2089, "advance_count" : 4, "score" : 1842, "build_scorer_count" : 7, "create_weight" : 17760, "shallow_advance" : 1105, "create_weight_count" : 1, "build_scorer" : 10504 } }, { "type" : "TermQuery", "description" : "name.keyword:A", "time_in_nanos" : 5987, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 0, "shallow_advance_count" : 0, "set_min_competitive_score" : 0, "next_doc" : 0, "match" : 0, "next_doc_count" : 0, "score_count" : 0, "compute_max_score_count" : 0, "compute_max_score" : 0, "advance" : 0, "advance_count" : 0, "score" : 0, "build_scorer_count" : 5, "create_weight" : 5686, "shallow_advance" : 0, "create_weight_count" : 1, "build_scorer" : 295 } }, { "type" : "MatchNoDocsQuery", "description" : """MatchNoDocsQuery("failed [createDate] query, caused by number_format_exception:[For input string: "A"]")""", "time_in_nanos" : 1431, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 0, "shallow_advance_count" : 0, "set_min_competitive_score" : 0, "next_doc" : 0, "match" : 0, "next_doc_count" : 0, "score_count" : 0, "compute_max_score_count" : 0, "compute_max_score" : 0, "advance" : 0, "advance_count" : 0, "score" : 0, "build_scorer_count" : 5, "create_weight" : 788, "shallow_advance" : 0, "create_weight_count" : 1, "build_scorer" : 637 } }, { "type" : "TermQuery", "description" : "desc:a", "time_in_nanos" : 18791, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 0, "shallow_advance_count" : 4, "set_min_competitive_score" : 0, "next_doc" : 337, "match" : 0, "next_doc_count" : 2, "score_count" : 3, "compute_max_score_count" : 2, "compute_max_score" : 650, "advance" : 242, "advance_count" : 4, "score" : 284, "build_scorer_count" : 8, "create_weight" : 11047, "shallow_advance" : 193, "create_weight_count" : 1, "build_scorer" : 6014 } } ] } ], "rewrite_time" : 3942, "collector" : [ { "name" : "CancellableCollector", "reason" : "search_cancelled", "time_in_nanos" : 14481, "children" : [ { "name" : "SimpleTopScoreDocCollector", "reason" : "search_top_hits", "time_in_nanos" : 10374 } ] } ] } ], "aggregations" : [ ] } ] } } ### 3 desc字段查询Beautiful ### \# Mind为泛查询 在所有字段查询 \# 合并2个条件的结果集 get goods/\_search?q=desc:Beautiful Mind \{ "profile":true \} { "took" : 1, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 4, "relation" : "eq" }, "max_score" : 1.0141646, "hits" : [ { "_index" : "goods", "_type" : "_doc", "_id" : "1", "_score" : 1.0141646, "_source" : { "name" : "apple A", "desc" : "Beautiful Mind A", "createDate" : 2001 } }, { "_index" : "goods", "_type" : "_doc", "_id" : "2", "_score" : 1.0141646, "_source" : { "name" : "apple B", "desc" : "Beautiful Mind B", "createDate" : 2010 } }, { "_index" : "goods", "_type" : "_doc", "_id" : "3", "_score" : 0.5951853, "_source" : { "name" : "orange A", "desc" : "Beautiful A", "createDate" : 2009 } }, { "_index" : "goods", "_type" : "_doc", "_id" : "4", "_score" : 0.5951853, "_source" : { "name" : "orange B", "desc" : "Mind A", "createDate" : 2009 } } ] }, "profile" : { "shards" : [ { "id" : "[GiqyrgdeRXmHsb5T6U1N4Q][goods][0]", "searches" : [ { "query" : [ { "type" : "BooleanQuery", "description" : """desc:beautiful (desc.keyword:Mind | name:mind | name.keyword:Mind | MatchNoDocsQuery("failed [createDate] query, caused by number_format_exception:[For input string: "Mind"]") | desc:mind)""", "time_in_nanos" : 295587, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 2, "shallow_advance_count" : 0, "set_min_competitive_score" : 0, "next_doc" : 24890, "match" : 767, "next_doc_count" : 8, "score_count" : 4, "compute_max_score_count" : 0, "compute_max_score" : 0, "advance" : 0, "advance_count" : 0, "score" : 4699, "build_scorer_count" : 9, "create_weight" : 77474, "shallow_advance" : 0, "create_weight_count" : 1, "build_scorer" : 187733 }, "children" : [ { "type" : "TermQuery", "description" : "desc:beautiful", "time_in_nanos" : 59653, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 0, "shallow_advance_count" : 6, "set_min_competitive_score" : 0, "next_doc" : 466, "match" : 0, "next_doc_count" : 2, "score_count" : 3, "compute_max_score_count" : 6, "compute_max_score" : 5519, "advance" : 382, "advance_count" : 4, "score" : 2481, "build_scorer_count" : 11, "create_weight" : 32825, "shallow_advance" : 1736, "create_weight_count" : 1, "build_scorer" : 16211 } }, { "type" : "DisjunctionMaxQuery", "description" : """(desc.keyword:Mind | name:mind | name.keyword:Mind | MatchNoDocsQuery("failed [createDate] query, caused by number_format_exception:[For input string: "Mind"]") | desc:mind)""", "time_in_nanos" : 125783, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 0, "shallow_advance_count" : 6, "set_min_competitive_score" : 0, "next_doc" : 291, "match" : 0, "next_doc_count" : 2, "score_count" : 3, "compute_max_score_count" : 6, "compute_max_score" : 1225, "advance" : 2642, "advance_count" : 4, "score" : 630, "build_scorer_count" : 11, "create_weight" : 36612, "shallow_advance" : 826, "create_weight_count" : 1, "build_scorer" : 83524 }, "children" : [ { "type" : "TermQuery", "description" : "desc.keyword:Mind", "time_in_nanos" : 8497, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 0, "shallow_advance_count" : 0, "set_min_competitive_score" : 0, "next_doc" : 0, "match" : 0, "next_doc_count" : 0, "score_count" : 0, "compute_max_score_count" : 0, "compute_max_score" : 0, "advance" : 0, "advance_count" : 0, "score" : 0, "build_scorer_count" : 5, "create_weight" : 8054, "shallow_advance" : 0, "create_weight_count" : 1, "build_scorer" : 437 } }, { "type" : "TermQuery", "description" : "name:mind", "time_in_nanos" : 7966, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 0, "shallow_advance_count" : 0, "set_min_competitive_score" : 0, "next_doc" : 0, "match" : 0, "next_doc_count" : 0, "score_count" : 0, "compute_max_score_count" : 0, "compute_max_score" : 0, "advance" : 0, "advance_count" : 0, "score" : 0, "build_scorer_count" : 5, "create_weight" : 7708, "shallow_advance" : 0, "create_weight_count" : 1, "build_scorer" : 252 } }, { "type" : "TermQuery", "description" : "name.keyword:Mind", "time_in_nanos" : 5540, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 0, "shallow_advance_count" : 0, "set_min_competitive_score" : 0, "next_doc" : 0, "match" : 0, "next_doc_count" : 0, "score_count" : 0, "compute_max_score_count" : 0, "compute_max_score" : 0, "advance" : 0, "advance_count" : 0, "score" : 0, "build_scorer_count" : 5, "create_weight" : 5272, "shallow_advance" : 0, "create_weight_count" : 1, "build_scorer" : 262 } }, { "type" : "MatchNoDocsQuery", "description" : """MatchNoDocsQuery("failed [createDate] query, caused by number_format_exception:[For input string: "Mind"]")""", "time_in_nanos" : 1045, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 0, "shallow_advance_count" : 0, "set_min_competitive_score" : 0, "next_doc" : 0, "match" : 0, "next_doc_count" : 0, "score_count" : 0, "compute_max_score_count" : 0, "compute_max_score" : 0, "advance" : 0, "advance_count" : 0, "score" : 0, "build_scorer_count" : 5, "create_weight" : 388, "shallow_advance" : 0, "create_weight_count" : 1, "build_scorer" : 651 } }, { "type" : "TermQuery", "description" : "desc:mind", "time_in_nanos" : 81043, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 0, "shallow_advance_count" : 6, "set_min_competitive_score" : 0, "next_doc" : 166, "match" : 0, "next_doc_count" : 2, "score_count" : 3, "compute_max_score_count" : 6, "compute_max_score" : 830, "advance" : 2161, "advance_count" : 4, "score" : 374, "build_scorer_count" : 8, "create_weight" : 9482, "shallow_advance" : 282, "create_weight_count" : 1, "build_scorer" : 67718 } } ] } ] } ], "rewrite_time" : 10074, "collector" : [ { "name" : "CancellableCollector", "reason" : "search_cancelled", "time_in_nanos" : 14509, "children" : [ { "name" : "SimpleTopScoreDocCollector", "reason" : "search_top_hits", "time_in_nanos" : 9707 } ] } ] } ], "aggregations" : [ ] } ] } } ### 4 词组查询(phrase) ### get goods/\_search?q=desc:"Beautiful Mind" \{ "profile":true \} { "took" : 1, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 2, "relation" : "eq" }, "max_score" : 1.0141646, "hits" : [ { "_index" : "goods", "_type" : "_doc", "_id" : "1", "_score" : 1.0141646, "_source" : { "name" : "apple A", "desc" : "Beautiful Mind A", "createDate" : 2001 } }, { "_index" : "goods", "_type" : "_doc", "_id" : "2", "_score" : 1.0141646, "_source" : { "name" : "apple B", "desc" : "Beautiful Mind B", "createDate" : 2010 } } ] }, "profile" : { "shards" : [ { "id" : "[GiqyrgdeRXmHsb5T6U1N4Q][goods][0]", "searches" : [ { "query" : [ { "type" : "PhraseQuery", "description" : """desc:"beautiful mind"""", "time_in_nanos" : 210207, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 2, "shallow_advance_count" : 0, "set_min_competitive_score" : 0, "next_doc" : 4472, "match" : 11048, "next_doc_count" : 4, "score_count" : 2, "compute_max_score_count" : 0, "compute_max_score" : 0, "advance" : 0, "advance_count" : 0, "score" : 3894, "build_scorer_count" : 7, "create_weight" : 74557, "shallow_advance" : 0, "create_weight_count" : 1, "build_scorer" : 116220 } } ], "rewrite_time" : 3214, "collector" : [ { "name" : "CancellableCollector", "reason" : "search_cancelled", "time_in_nanos" : 13281, "children" : [ { "name" : "SimpleTopScoreDocCollector", "reason" : "search_top_hits", "time_in_nanos" : 8552 } ] } ] } ], "aggregations" : [ ] } ] } } ### 5 布尔查询 OR ### \# desc 查询Beautiful \# desc 查询Mind \# 合并2个结果集 get goods/\_search?q=desc:(Beautiful Mind) \{ "profile":true \} { "took" : 1, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 4, "relation" : "eq" }, "max_score" : 1.0141646, "hits" : [ { "_index" : "goods", "_type" : "_doc", "_id" : "1", "_score" : 1.0141646, "_source" : { "name" : "apple A", "desc" : "Beautiful Mind A", "createDate" : 2001 } }, { "_index" : "goods", "_type" : "_doc", "_id" : "2", "_score" : 1.0141646, "_source" : { "name" : "apple B", "desc" : "Beautiful Mind B", "createDate" : 2010 } }, { "_index" : "goods", "_type" : "_doc", "_id" : "3", "_score" : 0.5951853, "_source" : { "name" : "orange A", "desc" : "Beautiful A", "createDate" : 2009 } }, { "_index" : "goods", "_type" : "_doc", "_id" : "4", "_score" : 0.5951853, "_source" : { "name" : "orange B", "desc" : "Mind A", "createDate" : 2009 } } ] }, "profile" : { "shards" : [ { "id" : "[GiqyrgdeRXmHsb5T6U1N4Q][goods][0]", "searches" : [ { "query" : [ { "type" : "BooleanQuery", "description" : "desc:beautiful desc:mind", "time_in_nanos" : 339538, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 2, "shallow_advance_count" : 0, "set_min_competitive_score" : 0, "next_doc" : 38074, "match" : 1408, "next_doc_count" : 8, "score_count" : 4, "compute_max_score_count" : 0, "compute_max_score" : 0, "advance" : 0, "advance_count" : 0, "score" : 7132, "build_scorer_count" : 9, "create_weight" : 67963, "shallow_advance" : 0, "create_weight_count" : 1, "build_scorer" : 224937 }, "children" : [ { "type" : "TermQuery", "description" : "desc:beautiful", "time_in_nanos" : 85180, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 0, "shallow_advance_count" : 6, "set_min_competitive_score" : 0, "next_doc" : 859, "match" : 0, "next_doc_count" : 2, "score_count" : 3, "compute_max_score_count" : 6, "compute_max_score" : 5983, "advance" : 446, "advance_count" : 4, "score" : 3659, "build_scorer_count" : 11, "create_weight" : 41865, "shallow_advance" : 2348, "create_weight_count" : 1, "build_scorer" : 29987 } }, { "type" : "TermQuery", "description" : "desc:mind", "time_in_nanos" : 31923, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 0, "shallow_advance_count" : 6, "set_min_competitive_score" : 0, "next_doc" : 328, "match" : 0, "next_doc_count" : 2, "score_count" : 3, "compute_max_score_count" : 6, "compute_max_score" : 3005, "advance" : 2944, "advance_count" : 4, "score" : 453, "build_scorer_count" : 11, "create_weight" : 16497, "shallow_advance" : 1104, "create_weight_count" : 1, "build_scorer" : 7559 } } ] } ], "rewrite_time" : 10289, "collector" : [ { "name" : "CancellableCollector", "reason" : "search_cancelled", "time_in_nanos" : 22666, "children" : [ { "name" : "SimpleTopScoreDocCollector", "reason" : "search_top_hits", "time_in_nanos" : 15331 } ] } ] } ], "aggregations" : [ ] } ] } } ### 6 布尔查询 NOT 必须不含有 ### \# Beautiful 和 Mind的 OR结果集中且必须不包含Mind \# desc 查询不包含Mind 但含有Beautiful get goods/\_search?q=desc:(Beautiful NOT Mind) \{ "profile":true \} { "took" : 3, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 1, "relation" : "eq" }, "max_score" : 0.5951853, "hits" : [ { "_index" : "goods", "_type" : "_doc", "_id" : "3", "_score" : 0.5951853, "_source" : { "name" : "orange A", "desc" : "Beautiful A", "createDate" : 2009 } } ] }, "profile" : { "shards" : [ { "id" : "[GiqyrgdeRXmHsb5T6U1N4Q][goods][0]", "searches" : [ { "query" : [ { "type" : "BooleanQuery", "description" : "desc:beautiful -desc:mind", "time_in_nanos" : 296267, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 2, "shallow_advance_count" : 0, "set_min_competitive_score" : 0, "next_doc" : 6714, "match" : 9021, "next_doc_count" : 6, "score_count" : 1, "compute_max_score_count" : 0, "compute_max_score" : 0, "advance" : 0, "advance_count" : 0, "score" : 3559, "build_scorer_count" : 8, "create_weight" : 99846, "shallow_advance" : 0, "create_weight_count" : 1, "build_scorer" : 177109 }, "children" : [ { "type" : "TermQuery", "description" : "desc:beautiful", "time_in_nanos" : 116450, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 0, "shallow_advance_count" : 0, "set_min_competitive_score" : 0, "next_doc" : 4761, "match" : 0, "next_doc_count" : 6, "score_count" : 1, "compute_max_score_count" : 0, "compute_max_score" : 0, "advance" : 0, "advance_count" : 0, "score" : 3266, "build_scorer_count" : 11, "create_weight" : 69753, "shallow_advance" : 0, "create_weight_count" : 1, "build_scorer" : 38651 } }, { "type" : "TermQuery", "description" : "desc:mind", "time_in_nanos" : 61061, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 0, "shallow_advance_count" : 0, "set_min_competitive_score" : 0, "next_doc" : 0, "match" : 0, "next_doc_count" : 0, "score_count" : 0, "compute_max_score_count" : 0, "compute_max_score" : 0, "advance" : 611, "advance_count" : 2, "score" : 0, "build_scorer_count" : 7, "create_weight" : 13431, "shallow_advance" : 0, "create_weight_count" : 1, "build_scorer" : 47009 } } ] } ], "rewrite_time" : 31199, "collector" : [ { "name" : "CancellableCollector", "reason" : "search_cancelled", "time_in_nanos" : 22285, "children" : [ { "name" : "SimpleTopScoreDocCollector", "reason" : "search_top_hits", "time_in_nanos" : 12707 } ] } ] } ], "aggregations" : [ ] } ] } } ### 7 布尔查询 AND ### \# desc 查询含有Beautiful 且 含有Mind get goods/\_search?q=desc:(Beautiful AND Mind) \{ "profile":true \} { "took" : 1, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 2, "relation" : "eq" }, "max_score" : 1.0141646, "hits" : [ { "_index" : "goods", "_type" : "_doc", "_id" : "1", "_score" : 1.0141646, "_source" : { "name" : "apple A", "desc" : "Beautiful Mind A", "createDate" : 2001 } }, { "_index" : "goods", "_type" : "_doc", "_id" : "2", "_score" : 1.0141646, "_source" : { "name" : "apple B", "desc" : "Beautiful Mind B", "createDate" : 2010 } } ] }, "profile" : { "shards" : [ { "id" : "[Y-IVdbuvQIuqKymA9zR6dw][goods][0]", "searches" : [ { "query" : [ { "type" : "BooleanQuery", "description" : "+desc:beautiful +desc:mind", "time_in_nanos" : 231894, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 0, "shallow_advance_count" : 0, "set_min_competitive_score" : 0, "next_doc" : 18170, "match" : 0, "next_doc_count" : 4, "score_count" : 2, "compute_max_score_count" : 0, "compute_max_score" : 0, "advance" : 0, "advance_count" : 0, "score" : 355, "build_scorer_count" : 7, "create_weight" : 78878, "shallow_advance" : 0, "create_weight_count" : 1, "build_scorer" : 134477 }, "children" : [ { "type" : "TermQuery", "description" : "desc:beautiful", "time_in_nanos" : 124287, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 0, "shallow_advance_count" : 6, "set_min_competitive_score" : 0, "next_doc" : 0, "match" : 0, "next_doc_count" : 0, "score_count" : 2, "compute_max_score_count" : 6, "compute_max_score" : 34658, "advance" : 1330, "advance_count" : 4, "score" : 1511, "build_scorer_count" : 9, "create_weight" : 51742, "shallow_advance" : 1671, "create_weight_count" : 1, "build_scorer" : 33347 } }, { "type" : "TermQuery", "description" : "desc:mind", "time_in_nanos" : 31687, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 0, "shallow_advance_count" : 6, "set_min_competitive_score" : 0, "next_doc" : 0, "match" : 0, "next_doc_count" : 0, "score_count" : 2, "compute_max_score_count" : 8, "compute_max_score" : 8216, "advance" : 127, "advance_count" : 2, "score" : 153, "build_scorer_count" : 7, "create_weight" : 16803, "shallow_advance" : 314, "create_weight_count" : 1, "build_scorer" : 6048 } } ] } ], "rewrite_time" : 13626, "collector" : [ { "name" : "CancellableCollector", "reason" : "search_cancelled", "time_in_nanos" : 11094, "children" : [ { "name" : "SimpleTopScoreDocCollector", "reason" : "search_top_hits", "time_in_nanos" : 5914 } ] } ] } ], "aggregations" : [ ] } ] } } ### 8 布尔查询 必须含有 ### \# Beautiful和Mind的OR结果集中且必须包含Mind \# desc 查询 含Mind Beautiful可以有可以没有 get goods/\_search?q=desc:(Beautiful %2BMind) \{ "profile":true \} { "took" : 1, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 3, "relation" : "eq" }, "max_score" : 1.0141646, "hits" : [ { "_index" : "goods", "_type" : "_doc", "_id" : "1", "_score" : 1.0141646, "_source" : { "name" : "apple A", "desc" : "Beautiful Mind A", "createDate" : 2001 } }, { "_index" : "goods", "_type" : "_doc", "_id" : "2", "_score" : 1.0141646, "_source" : { "name" : "apple B", "desc" : "Beautiful Mind B", "createDate" : 2010 } }, { "_index" : "goods", "_type" : "_doc", "_id" : "4", "_score" : 0.5951853, "_source" : { "name" : "orange B", "desc" : "Mind A", "createDate" : 2009 } } ] }, "profile" : { "shards" : [ { "id" : "[GiqyrgdeRXmHsb5T6U1N4Q][goods][0]", "searches" : [ { "query" : [ { "type" : "BooleanQuery", "description" : "desc:beautiful +desc:mind", "time_in_nanos" : 151190, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 0, "shallow_advance_count" : 0, "set_min_competitive_score" : 0, "next_doc" : 6827, "match" : 0, "next_doc_count" : 6, "score_count" : 3, "compute_max_score_count" : 0, "compute_max_score" : 0, "advance" : 0, "advance_count" : 0, "score" : 4459, "build_scorer_count" : 8, "create_weight" : 72242, "shallow_advance" : 0, "create_weight_count" : 1, "build_scorer" : 67644 }, "children" : [ { "type" : "TermQuery", "description" : "desc:beautiful", "time_in_nanos" : 63204, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 0, "shallow_advance_count" : 4, "set_min_competitive_score" : 0, "next_doc" : 0, "match" : 0, "next_doc_count" : 0, "score_count" : 2, "compute_max_score_count" : 2, "compute_max_score" : 273, "advance" : 97, "advance_count" : 2, "score" : 145, "build_scorer_count" : 7, "create_weight" : 49830, "shallow_advance" : 164, "create_weight_count" : 1, "build_scorer" : 12677 } }, { "type" : "TermQuery", "description" : "desc:mind", "time_in_nanos" : 30463, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 0, "shallow_advance_count" : 4, "set_min_competitive_score" : 0, "next_doc" : 356, "match" : 0, "next_doc_count" : 2, "score_count" : 3, "compute_max_score_count" : 4, "compute_max_score" : 4304, "advance" : 1695, "advance_count" : 4, "score" : 2545, "build_scorer_count" : 11, "create_weight" : 12245, "shallow_advance" : 1073, "create_weight_count" : 1, "build_scorer" : 8216 } } ] } ], "rewrite_time" : 9561, "collector" : [ { "name" : "CancellableCollector", "reason" : "search_cancelled", "time_in_nanos" : 13144, "children" : [ { "name" : "SimpleTopScoreDocCollector", "reason" : "search_top_hits", "time_in_nanos" : 9243 } ] } ] } ], "aggregations" : [ ] } ] } } ### 9 范围查询\[\] 闭区间,\{\} 开区间 ### \# createDate 查询2001及以后的文档 get goods/\_search?q=desc:Beautiful AND createDate:\[2001 TO \*\] \{ "profile":true \} { "took" : 1, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 3, "relation" : "eq" }, "max_score" : 1.5951853, "hits" : [ { "_index" : "goods", "_type" : "_doc", "_id" : "3", "_score" : 1.5951853, "_source" : { "name" : "orange A", "desc" : "Beautiful A", "createDate" : 2009 } }, { "_index" : "goods", "_type" : "_doc", "_id" : "1", "_score" : 1.5070822, "_source" : { "name" : "apple A", "desc" : "Beautiful Mind A", "createDate" : 2001 } }, { "_index" : "goods", "_type" : "_doc", "_id" : "2", "_score" : 1.5070822, "_source" : { "name" : "apple B", "desc" : "Beautiful Mind B", "createDate" : 2010 } } ] }, "profile" : { "shards" : [ { "id" : "[GiqyrgdeRXmHsb5T6U1N4Q][goods][0]", "searches" : [ { "query" : [ { "type" : "BooleanQuery", "description" : "+desc:beautiful +createDate:[2001 TO 9223372036854775807]", "time_in_nanos" : 141341, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 0, "shallow_advance_count" : 0, "set_min_competitive_score" : 0, "next_doc" : 19643, "match" : 0, "next_doc_count" : 6, "score_count" : 3, "compute_max_score_count" : 0, "compute_max_score" : 0, "advance" : 0, "advance_count" : 0, "score" : 322, "build_scorer_count" : 8, "create_weight" : 43138, "shallow_advance" : 0, "create_weight_count" : 1, "build_scorer" : 78220 }, "children" : [ { "type" : "TermQuery", "description" : "desc:beautiful", "time_in_nanos" : 63756, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 0, "shallow_advance_count" : 9, "set_min_competitive_score" : 0, "next_doc" : 0, "match" : 0, "next_doc_count" : 0, "score_count" : 3, "compute_max_score_count" : 9, "compute_max_score" : 4524, "advance" : 1948, "advance_count" : 6, "score" : 2189, "build_scorer_count" : 11, "create_weight" : 34479, "shallow_advance" : 1604, "create_weight_count" : 1, "build_scorer" : 18973 } }, { "type" : "IndexOrDocValuesQuery", "description" : "createDate:[2001 TO 9223372036854775807]", "time_in_nanos" : 18065, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 0, "shallow_advance_count" : 9, "set_min_competitive_score" : 0, "next_doc" : 0, "match" : 0, "next_doc_count" : 0, "score_count" : 3, "compute_max_score_count" : 12, "compute_max_score" : 1194, "advance" : 1116, "advance_count" : 3, "score" : 489, "build_scorer_count" : 9, "create_weight" : 1397, "shallow_advance" : 573, "create_weight_count" : 1, "build_scorer" : 13259 } } ] } ], "rewrite_time" : 8388, "collector" : [ { "name" : "CancellableCollector", "reason" : "search_cancelled", "time_in_nanos" : 8135, "children" : [ { "name" : "SimpleTopScoreDocCollector", "reason" : "search_top_hits", "time_in_nanos" : 4141 } ] } ] } ], "aggregations" : [ ] } ] } } ### 10 通配符查询 ### \# name 查询 fruit开始的文档 get goods/\_search?q=name:fruit\* \{ "profile":true \} { "took" : 1, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 1, "relation" : "eq" }, "max_score" : 1.0, "hits" : [ { "_index" : "goods", "_type" : "_doc", "_id" : "5", "_score" : 1.0, "_source" : { "name" : "fruit F", "desc" : "F F F", "createDate" : 2009 } } ] }, "profile" : { "shards" : [ { "id" : "[GiqyrgdeRXmHsb5T6U1N4Q][goods][0]", "searches" : [ { "query" : [ { "type" : "MultiTermQueryConstantScoreWrapper", "description" : "name:fruit*", "time_in_nanos" : 105484, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 0, "shallow_advance_count" : 0, "set_min_competitive_score" : 0, "next_doc" : 531, "match" : 0, "next_doc_count" : 2, "score_count" : 1, "compute_max_score_count" : 0, "compute_max_score" : 0, "advance" : 0, "advance_count" : 0, "score" : 249, "build_scorer_count" : 6, "create_weight" : 3062, "shallow_advance" : 0, "create_weight_count" : 1, "build_scorer" : 101632 } }, { "type" : "MatchNoDocsQuery", "description" : """MatchNoDocsQuery("empty BooleanQuery")""", "time_in_nanos" : 3843, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 0, "shallow_advance_count" : 0, "set_min_competitive_score" : 0, "next_doc" : 0, "match" : 0, "next_doc_count" : 0, "score_count" : 0, "compute_max_score_count" : 0, "compute_max_score" : 0, "advance" : 0, "advance_count" : 0, "score" : 0, "build_scorer_count" : 1, "create_weight" : 1283, "shallow_advance" : 0, "create_weight_count" : 1, "build_scorer" : 2558 } }, { "type" : "MatchNoDocsQuery", "description" : """MatchNoDocsQuery("empty BooleanQuery")""", "time_in_nanos" : 619, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 0, "shallow_advance_count" : 0, "set_min_competitive_score" : 0, "next_doc" : 0, "match" : 0, "next_doc_count" : 0, "score_count" : 0, "compute_max_score_count" : 0, "compute_max_score" : 0, "advance" : 0, "advance_count" : 0, "score" : 0, "build_scorer_count" : 1, "create_weight" : 231, "shallow_advance" : 0, "create_weight_count" : 1, "build_scorer" : 386 } }, { "type" : "MatchNoDocsQuery", "description" : """MatchNoDocsQuery("empty BooleanQuery")""", "time_in_nanos" : 585, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 0, "shallow_advance_count" : 0, "set_min_competitive_score" : 0, "next_doc" : 0, "match" : 0, "next_doc_count" : 0, "score_count" : 0, "compute_max_score_count" : 0, "compute_max_score" : 0, "advance" : 0, "advance_count" : 0, "score" : 0, "build_scorer_count" : 1, "create_weight" : 167, "shallow_advance" : 0, "create_weight_count" : 1, "build_scorer" : 416 } }, { "type" : "MatchNoDocsQuery", "description" : """MatchNoDocsQuery("empty BooleanQuery")""", "time_in_nanos" : 538, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 0, "shallow_advance_count" : 0, "set_min_competitive_score" : 0, "next_doc" : 0, "match" : 0, "next_doc_count" : 0, "score_count" : 0, "compute_max_score_count" : 0, "compute_max_score" : 0, "advance" : 0, "advance_count" : 0, "score" : 0, "build_scorer_count" : 1, "create_weight" : 88, "shallow_advance" : 0, "create_weight_count" : 1, "build_scorer" : 448 } }, { "type" : "TermQuery", "description" : "name:fruit", "time_in_nanos" : 13136, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 0, "shallow_advance_count" : 0, "set_min_competitive_score" : 0, "next_doc" : 411, "match" : 0, "next_doc_count" : 2, "score_count" : 0, "compute_max_score_count" : 0, "compute_max_score" : 0, "advance" : 0, "advance_count" : 0, "score" : 0, "build_scorer_count" : 2, "create_weight" : 4047, "shallow_advance" : 0, "create_weight_count" : 1, "build_scorer" : 8673 } } ], "rewrite_time" : 8568, "collector" : [ { "name" : "CancellableCollector", "reason" : "search_cancelled", "time_in_nanos" : 8494, "children" : [ { "name" : "SimpleTopScoreDocCollector", "reason" : "search_top_hits", "time_in_nanos" : 5284 } ] } ] } ], "aggregations" : [ ] } ] } } ### 11 模糊匹配 近似度 term允许错误或缺失字符 最多允许2个字符 可以是 0 1 2 ### get goods/\_search?q=desc:beautifl~1 \{ "profile":true \} { "took" : 5, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 3, "relation" : "eq" }, "max_score" : 0.54608864, "hits" : [ { "_index" : "goods", "_type" : "_doc", "_id" : "3", "_score" : 0.54608864, "_source" : { "name" : "orange A", "desc" : "Beautiful A", "createDate" : 2009 } }, { "_index" : "goods", "_type" : "_doc", "_id" : "1", "_score" : 0.47162196, "_source" : { "name" : "apple A", "desc" : "Beautiful Mind A", "createDate" : 2001 } }, { "_index" : "goods", "_type" : "_doc", "_id" : "2", "_score" : 0.47162196, "_source" : { "name" : "apple B", "desc" : "Beautiful Mind B", "createDate" : 2010 } } ] }, "profile" : { "shards" : [ { "id" : "[GiqyrgdeRXmHsb5T6U1N4Q][goods][0]", "searches" : [ { "query" : [ { "type" : "BoostQuery", "description" : "(desc:beautiful)^0.875", "time_in_nanos" : 90363, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 0, "shallow_advance_count" : 0, "set_min_competitive_score" : 0, "next_doc" : 5339, "match" : 0, "next_doc_count" : 6, "score_count" : 3, "compute_max_score_count" : 0, "compute_max_score" : 0, "advance" : 0, "advance_count" : 0, "score" : 28719, "build_scorer_count" : 8, "create_weight" : 18020, "shallow_advance" : 0, "create_weight_count" : 1, "build_scorer" : 38267 } } ], "rewrite_time" : 752806, "collector" : [ { "name" : "CancellableCollector", "reason" : "search_cancelled", "time_in_nanos" : 47975, "children" : [ { "name" : "SimpleTopScoreDocCollector", "reason" : "search_top_hits", "time_in_nanos" : 40530 } ] } ] } ], "aggregations" : [ ] } ] } } ### 12 模糊匹配 近似度 phrase允许错误或丢失2个词(最多可设置2个) ### 重新插入一条测试数据,用desc测试丢失2个词的查询结果 post goods/\_doc/5 \{ "name":"fruit F", "desc":"goods is a good idea", "createDate":2009 \} get goods/\_search?q=desc:"goods good"~2 \{ "profile":true \} { "took" : 2, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 1, "relation" : "eq" }, "max_score" : 0.9530774, "hits" : [ { "_index" : "goods", "_type" : "_doc", "_id" : "5", "_score" : 0.9530774, "_source" : { "name" : "fruit F", "desc" : "goods is a good idea", "createDate" : 2009 } } ] }, "profile" : { "shards" : [ { "id" : "[GiqyrgdeRXmHsb5T6U1N4Q][goods][0]", "searches" : [ { "query" : [ { "type" : "PhraseQuery", "description" : """desc:"goods good"~2""", "time_in_nanos" : 243012, "breakdown" : { "set_min_competitive_score_count" : 0, "match_count" : 1, "shallow_advance_count" : 0, "set_min_competitive_score" : 0, "next_doc" : 2917, "match" : 17497, "next_doc_count" : 2, "score_count" : 1, "compute_max_score_count" : 0, "compute_max_score" : 0, "advance" : 0, "advance_count" : 0, "score" : 2846, "build_scorer_count" : 6, "create_weight" : 90486, "shallow_advance" : 0, "create_weight_count" : 1, "build_scorer" : 129255 } } ], "rewrite_time" : 6767, "collector" : [ { "name" : "CancellableCollector", "reason" : "search_cancelled", "time_in_nanos" : 13938, "children" : [ { "name" : "SimpleTopScoreDocCollector", "reason" : "search_top_hits", "time_in_nanos" : 9038 } ] } ] } ], "aggregations" : [ ] } ] } }
相关 Elasticsearch7.x——High Level REST Client(二)Search/Sync Search APIs 目录 7、Search APIs 7.1、SearchSourceBuilder 7.1.1、排序(SortB 太过爱你忘了你带给我的痛/ 2024年02月21日 11:13/ 0 赞/ 54 阅读
相关 Elasticsearch Search API 当执行一个搜索时,它将这个搜索请求广播给所有的索引分片。可以通过提供路由参数来控制要搜索哪些分片。例如,当检索tweets这个索引时,路由参数可以设置为用户名: ![复制代码 秒速五厘米/ 2023年01月14日 01:51/ 0 赞/ 171 阅读
相关 search API(三) request body方式 Request Body方式查询 一 先初始化数据 post /goods/_doc/1 { "name":"apple A", 阳光穿透心脏的1/2处/ 2022年12月17日 10:56/ 0 赞/ 112 阅读
相关 search API (二) request uri方式查询 search 查询需注意: ()表示分组,括号里的多种值应用于同一个字段,比如 name:(zhangsan lisi),查询name为zhangsan或者lisi的文档 柔情只为你懂/ 2022年12月16日 13:16/ 0 赞/ 136 阅读
相关 search API (一) 基础 一 search API概览 1 查询所有索引下的文档 GET \_search \{ "query": \{ "match\_a 梦里梦外;/ 2022年12月15日 06:30/ 0 赞/ 113 阅读
相关 ElasticSearch: Search API 查询用法详解 Search API ElasticSearch 为了搜索提供了一些原始的 API,主要是有两大类 URL Search URL Search 类似 刺骨的言语ヽ痛彻心扉/ 2022年12月04日 01:23/ 0 赞/ 198 阅读
相关 通用的uri匹配方式 package com.kiiik.vas.example.controller; import java.util.ArrayList; i 今天药忘吃喽~/ 2022年05月20日 10:12/ 0 赞/ 165 阅读
相关 nginx 414 Request-URI Too Large 客户端请求头缓冲区大小,如果请求头总长度大于小于128k,则使用此缓冲区, 请求头总长度大于128k时使用large\_client\_header\_buffers设置的 女爷i/ 2022年05月18日 05:39/ 0 赞/ 160 阅读
相关 php request uri,PHP_SELF,PATH_INFO,SCRIPT_NAME,REQUEST_URI PATH\_INFO 仅在使用htaccess这样的情况下可用: 例子1 RewriteCond %\{REQUEST\_FILENAME\} !-f RewriteCo 清疚/ 2021年09月07日 06:20/ 0 赞/ 303 阅读
还没有评论,来说两句吧...