elasticsearch 기본 검색 2 (영어 분사)term와terms 검색

term과terms 조회(zhaoliu라는 사람의 정보를 찾습니다)termquery는 거꾸로 줄을 서서 활| 에서 정확한 term을 찾습니다. 분사기의 존재를 알지 못합니다.이런 검색은 키워드,numeric에 적합하다.date. term: 특정 필드에 키워드가 포함된 문서 검색 GET/lib3/user/_search/{"query": {interests":'changge'}}terms: 필드에 여러 키워드가 포함된 문서 GET/ib3/user/_search {"query": {"terms": {"interests": ["hejiu","changge"]}}}
GET /lib3/user/_search
{
  "query": {
    "term": {
      "name": {
        "value": "zhaoliu"
      }
    }
  }
}
 
 
GET /lib3/user/_search
{
  "query": {
    "term": {
      "name": "zhaoliu"
    }
  }
}
{
  "took" : 5,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 0.2876821,
    "hits" : [
      {
        "_index" : "lib3",
        "_type" : "user",
        "_id" : "1",
        "_score" : 0.2876821,
        "_source" : {
          "name" : "zhaoliu",
          "address" : "hei long jiang sheng tie ling shi",
          "age" : 50,
          "birthday" : "1970-12-12",
          "interests" : "xi buan hejiu, duanlian, lvyou"
        }
      }
    ]
  }
}

 
취미인interests가hejiuchangge인 사람 정보 찾기
GET /lib3/user/_search
{
  "query": {
    "terms": {
      "interests": ["hejiu","changge"]
    }
  }
}
{
  "took" : 56,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 4,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "lib3",
        "_type" : "user",
        "_id" : "5",
        "_score" : 1.0,
        "_source" : {
          "name" : "zhangsan",
          "address" : "bei jing chao yang qu",
          "age" : 29,
          "birthday" : "1988-10-12",
          "interests" : "xi huan tingyinyue , changge , tiaowu"
        }
      },
      {
        "_index" : "lib3",
        "_type" : "user",
        "_id" : "2",
        "_score" : 1.0,
        "_source" : {
          "name" : "zhaoming",
          "address" : "bei jing hai dian qu qing he zhen",
          "age" : 20,
          "birthday" : "1998-10-12",
          "interests" : "xi huan hejiu, duanlian, changge"
        }
      },
      {
        "_index" : "lib3",
        "_type" : "user",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "name" : "zhaoliu",
          "address" : "hei long jiang sheng tie ling shi",
          "age" : 50,
          "birthday" : "1970-12-12",
          "interests" : "xi buan hejiu, duanlian, lvyou"
        }
      },
      {
        "_index" : "lib3",
        "_type" : "user",
        "_id" : "3",
        "_score" : 1.0,
        "_source" : {
          "name" : "lisi",
          "address" : "bei jing hai dian qu qing he zhen",
          "age" : 23,
          "birthday" : "1998-10-12",
          "interests" : "xi huan hejiu,duanlian, changge"
        }
      }
    ]
  }
}

키워드 하나만 있으면 다 조회가 돼요. 총 4명이서 Hejiu changge, changge, Hejiu, 둘 다 있어요.
from:0 (첫 번째 문서부터) size:2 (두 개의 문서를 가져오는 것)
GET /lib3/user/_search
{
  "from":0,
  "size":2,
  "query": {
    "terms": {
      "interests": ["hejiu","changge"]
    }
  }
}
{
  "took" : 81,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 4,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "lib3",
        "_type" : "user",
        "_id" : "5",
        "_score" : 1.0,
        "_source" : {
          "name" : "zhangsan",
          "address" : "bei jing chao yang qu",
          "age" : 29,
          "birthday" : "1988-10-12",
          "interests" : "xi huan tingyinyue , changge , tiaowu"
        }
      },
      {
        "_index" : "lib3",
        "_type" : "user",
        "_id" : "2",
        "_score" : 1.0,
        "_source" : {
          "name" : "zhaoming",
          "address" : "bei jing hai dian qu qing he zhen",
          "age" : 20,
          "birthday" : "1998-10-12",
          "interests" : "xi huan hejiu, duanlian, changge"
        }
      }
    ]
  }
}

이상의 조회는 버전 번호가 없습니다. 버전 번호를 얻으려면version:true 하나만 추가하십시오
GET /lib3/user/_search
{
  "version": true, 
  "query": {
    "terms": {
      "interests": ["hejiu","changge"]
    }
  }
}
{
  "took" : 33,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 4,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "lib3",
        "_type" : "user",
        "_id" : "5",
        "_version" : 1,
        "_score" : 1.0,
        "_source" : {
          "name" : "zhangsan",
          "address" : "bei jing chao yang qu",
          "age" : 29,
          "birthday" : "1988-10-12",
          "interests" : "xi huan tingyinyue , changge , tiaowu"
        }
      },
      {
        "_index" : "lib3",
        "_type" : "user",
        "_id" : "2",
        "_version" : 1,
        "_score" : 1.0,
        "_source" : {
          "name" : "zhaoming",
          "address" : "bei jing hai dian qu qing he zhen",
          "age" : 20,
          "birthday" : "1998-10-12",
          "interests" : "xi huan hejiu, duanlian, changge"
        }
      },
      {
        "_index" : "lib3",
        "_type" : "user",
        "_id" : "1",
        "_version" : 1,
        "_score" : 1.0,
        "_source" : {
          "name" : "zhaoliu",
          "address" : "hei long jiang sheng tie ling shi",
          "age" : 50,
          "birthday" : "1970-12-12",
          "interests" : "xi buan hejiu, duanlian, lvyou"
        }
      },
      {
        "_index" : "lib3",
        "_type" : "user",
        "_id" : "3",
        "_version" : 1,
        "_score" : 1.0,
        "_source" : {
          "name" : "lisi",
          "address" : "bei jing hai dian qu qing he zhen",
          "age" : 23,
          "birthday" : "1998-10-12",
          "interests" : "xi huan hejiu,duanlian, changge"
        }
      }
    ]
  }
}

좋은 웹페이지 즐겨찾기