Query string方式

基础语法

GET /index名/type名/_search?q=field字段名:搜索关键词
GET /index名/type名/_search?q=+field字段名:搜索关键词
GET /index名/type名/_search?q=-field字段名:搜索关键词
  • 第一条的意思是对指定field字段搜索关键词document

  • 第二条的意思是对指定field字段搜索包含关键词的document(结果同第一条)

  • 第三条的意思是对指定field字段搜索不包含关键词的document

示例

GET /test_index/test_type/_search?q=test_field:test
GET /test_index/test_type/_search?q=+test_field:test
GET /test_index/test_type/_search?q=-test_field:test

也可以不指定具体的字段名,搜索所有字段中包含所要"搜索关键词"的doucment

GET /index名/type名/_search?q=搜索关键词

注意虽然没有指定具体字段名。但是es搜索时并不是对document中的每一个field都进行一次搜索.

es中的_有一个__all元数据字段名,在建立索引的时候,插入一条document,并包含了多个field,此时,es会自动将多个field的值,全部用字符串的方式串联起来组成一个字符串,作为_all 字段的值,同时进行分词后建立对应的倒排索引

后面如果在搜索的时候,没有指定具体字段名,就默认搜索_all 字段,

例子

"revin 27 509129@qq.com zhongguo",作为这一条document的_all 字段的值,同时进行分词后建立对应的倒排索引

Last updated

Was this helpful?