ElasticSearch Search

5BRack·2022년 10월 19일

백엔드 로드맵

목록 보기
18/28

CRUD

Create

[post] http://localhost:9200/myboard/_doc/1,
{
    "id":"123123",
    "title":"title",
    "contents":"contents"
}

Read

Update

[post] http://localhost:9200/myboard/_doc/1,
{
    "id":"12321312",
    "title":"수정",
    "contents":"contents"
}

Delete

{
    "acknowledged": true
}

Query DSL

  • elastic search 는 검색을 위한 쿼리 기능을 제공한다.

query 사용

  • query에서는 token이라는 개념이 들어간다.

  • token은 공백을 기준으로 단어를 나누어 검색을 하게 된다.

  • description에 키워드가 들어간 검색 쿼리

  • [post] http://localhost:9200/myproduct09/_search

// 쿼리
{
    "query":{
        "match":{
            "description":"Best"
        }
    }
}
// 결과
{
    "took": 445,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 1,
            "relation": "eq"
        },
        "max_score": 0.84290004,
        "hits": [
            {
                "_index": "myproduct09",
                "_type": "_doc",
                "_id": "1",
                "_score": 0.84290004,
                "_source": {
                    "name": "최신마우스",
                    "description": "안녕하세요. BestShop입니다! 국내 최고 Best 상품만 판매합니다!",
                    "price": 10000
                }
            }
        ]
    }
}

analyze

  • 어떻게 검색되는 지 분석이 가능하다.
//쿼리
http://localhost:9200/myproduct09/_analyze
body 
{
	"text":"안녕하세요. BestShop입니다! 국내 최고 Best 상품만 판매합니다!",
}
//결과 
{
    "tokens": [
        {
            "token": "안녕하세요",
            "start_offset": 0,
            "end_offset": 5,
            "type": "<HANGUL>",
            "position": 0
        },
        {
            "token": "bestshop입니다",
            "start_offset": 7,
            "end_offset": 18,
            "type": "<ALPHANUM>",
            "position": 1
        },
        {
            "token": "best",
            "start_offset": 20,
            "end_offset": 24,
            "type": "<ALPHANUM>",
            "position": 2
        }
    ]
}

x

0개의 댓글