1、query String 基础语法
GET test_index/test_type/_search?q=test_field:test //搜索指定index下的type中字段必须包含test_field:test的数据
GET test_index/test_type/_search?q=+test_field:test //搜索指定index下的type中字段必须包含test_field:test的数据
GET test_index/test_type/_search?q=-test_field:test //搜索指定index下的type中字段必须不包含test_field:test的数据
一个就是掌握q=field:search content,还有就是掌握+和-的含义
2、_all matedata的原理及作用
GET test_index/test_type/_search?q=test
可以搜索全部的field,任何一个field包含指定关键字就可以被搜索出来。
我们在进行搜索的时候,难道是对document中的每个field都进行一次搜索吗?不是的,es中的_all 元数据,在建立索引的时候,我们插入一条document,它里面包含多个field,此时,es会自动讲多个field的值,全部用字符串的方法串联起来,变成一个长的字符串,作为_all field的值,同时建立索引。
后面如果在搜索的时候,没有对某个field指定搜索,就默认搜索_all field,其中是包含了所有field的值。
举个例子:
{
"name":"jack",
"age":26,
"email":"jack@sina.com",
"adress":"english"
}
“jack 26 jack@sina.com english”,作为这一条document的_all field的值,同时进行分词后建立对应的倒排索引。