ElasticSearch语法学习(二)

#指定英文分词器的index创建
PUT /movie
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 1
  },
  "mappings": {
    "properties": {
      "name" :{
        "type": "text",
        "analyzer": "english"
      }
    }
  }
}
#tmdb海量数据测试
DELETE /movie
GET /movie/_search
PUT /movie
{
   "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 1
  },
  "mappings": {
    "properties": {
      "title" :{
        "type": "text",
        "analyzer": "english"
      },
      "tagline":{
        "type": "text",
        "analyzer": "english"
      },
      "release_date":{
        "type": "date",
        "format": "8yyyy/MM/dd||yyyy/M/dd||yyyy/MM/d||yyyy/M/d"
      },
      "popularity":{
        "type": "double"
      },
      "overview":{
         "type":"text",
        "analyzer": "english"
      },
      "cast":{
        "type": "object",
        "properties": {
          "character":{
            "type":"text",
            "analyzer": "standard"
          },
          "name":{
            "type":"text",
            "analyzer":"standard"
          }
        }
        
      }
    }
  }
}

#搜索  match
GET /movie/_search
{
  "query": {
    "match": {
      "title": "Steve Zissou"
    }
  }
}

GET /movie/_search
{
  "query": {
    "term": {
      "title": "Steve Zissou"
    }
  }
}
#查看分词器的分词内容
GET /movie/_analyze
{
  "field": "title",
  "text":"steve zissou"
}

#分词后or逻辑查询
GET /movie/_search
{
  "query": {
    "match": {
      "title": "basketball with cartoom aliens"
    }
  }
}

#分词后and 逻辑查询
GET /movie/_search
{
  "query": {
    "match": {
      "title":{
        "query": "basketball with cartoom aliens",
        "operator": "and"
      }
    }
  }
}

#最小词匹配项,最少有两个分词后的结果匹配
GET /movie/_search
{
  "query": {
    "match": {
      "title":{
        "query": "basketball with cartoom aliens",
        "operator": "or",
        "minimum_should_match": 2
      }
    }
  }
}

#短语查询,不对查询条件进行分词
GET /movie/_search
{
  "query": {
    "match_phrase": {
       "title":"steve zissou"
    }
  }
}

#多字段查询。对title和overview两个字段进行分词查询
GET /movie/_search
{
  "query": {
    "multi_match": {
      "query": "basketball with cartoom aliens",
      "fields": ["title","overview"]
    }
  }
}

#查看执行计划
GET /movie/_search
{
  "explain": true, 
  "query": {
    "match": {
      "title": "Steve Zissou"
    }
  }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值