es - elasticsearch - search - DSL - term level - ids

Source

世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程。

问:ids有什么特点?
答:
在这里插入图片描述
问:ids如何使用?
答:

# 删除
DELETE /ids_test

# 映射
PUT /ids_test
{
    
      
  "mappings": {
    
      
    "properties": {
    
      
      "name": {
    
      "type": "text"}
    }
  }
}

# 索引
POST /ids_test/_doc/1?refresh
{
    
      
  "name": "helol"
}

# 索引
POST /ids_test/_doc/2?refresh
{
    
      
  "name": "hollo good"
}

# 索引
POST /ids_test/_doc/3?refresh
{
    
      
  "name": "good ehllo"
}

# 索引
POST /ids_test/_doc/4?refresh
{
    
      
  "name": "hello hello"
}

# 搜索
GET /ids_test/_search
{
    
      
  "query": {
    
      
    "ids": {
    
      
      "values": ["1", "2", "3", "4"]
    }
  }
}

# 结果
{
    
      
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    
      
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    
      
    "total" : {
    
      
      "value" : 4,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
    
      
        "_index" : "ids_test",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
    
      
          "name" : "helol"
        }
      },
      {
    
      
        "_index" : "ids_test",
        "_type" : "_doc",
        "_id" : "2",
        "_score" : 1.0,
        "_source" : {
    
      
          "name" : "hollo good"
        }
      },
      {
    
      
        "_index" : "ids_test",
        "_type" : "_doc",
        "_id" : "3",
        "_score" : 1.0,
        "_source" : {
    
      
          "name" : "good ehllo"
        }
      },
      {
    
      
        "_index" : "ids_test",
        "_type" : "_doc",
        "_id" : "4",
        "_score" : 1.0,
        "_source" : {
    
      
          "name" : "hello hello"
        }
      }
    ]
  }
}