๊ธ€ ์ž‘์„ฑ์ž: ๋˜ฅํด๋ฒ .
๋ฐ˜์‘ํ˜•

 

์ „์ œ ์กฐ๊ฑด


fruit์ด๋ผ๋Š” index์— name์ด๋ผ๋Š” ํ•„๋“œ๊ฐ€ ์žˆ๊ณ  ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์—ฌ๋Ÿฌ ๊ฐœ์˜ document๋“ค์ด ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•˜์ž.

 

{"index":{}}
{"room_name": "๋ง๊ณ "}
{"index":{}}
{"room_name": "๋ง๊ณ ์Šคํ‹ด"}
{"index":{}}
{"room_name": "๋ง๊ณ ๋ง๊ณ ๋ง๊ณ "}
{"index":{}}
{"room_name": "๋ง๊ณ ๊ฐ€์ฌฌ์•„์ฌฌ์•„"}
{"index":{}}
{"room_name": "๋ง๊ณ ํ›„๋šœ๋ฃน"}
{"index":{}}
{"room_name": "๊น€๋ง๊ณ "}
{"index":{}}
{"room_name": "์„ธ์ƒ์—์„œ ์ œ์ผ ๋ง›์žˆ๋Š”๊ฑด ๋ง๊ณ ์ง€"}
์ƒค๋“œ์˜ ๊ฐฏ์ˆ˜๋Š” 3๊ฐœ
๊ฒ€์ƒ‰ ์•Œ๊ณ ๋ฆฌ์ฆ˜์€ BM25๋ฅผ ์‚ฌ์šฉ, tokenizer๋Š” ngram tokenizer(min:1) ์‚ฌ์šฉ.

 

 

 

๋ฌธ์ œ


๋‹ค์Œ๊ณผ ๊ฐ™์€ Query๋ฅผ ๋‚ ๋ฆฌ๋ฉด ์šฐ๋ฆฌ๋Š” "๋ง๊ณ "๊ฐ€ ๊ฐ€์žฅ 1์ˆœ์œ„๋กœ ์ถœ๋ ฅ๋  ๊ฒƒ์ด๋ผ๊ณ  ์˜ˆ์ƒ๋˜๋Š”๋ฐ

POST /_search
{
	"query": {
		"match": {
			"room_name": "๋ง๊ณ "
		}
	}
}
{
    "took": 16,
    "timed_out": false,
    "_shards": {
        "total": 3,
        "successful": 3,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 7,
            "relation": "eq"
        },
        "max_score": 0.2876821,
        "hits": [
            {
                "_index": "public_chat",
                "_type": "_doc",
                "_id": "fNTe0GwBME3K7rKzaiF0",
                "_score": 0.2876821,
                "_source": {
                    "room_name": "๋ง๊ณ ๊ฐ€์ฌฌ์•„์ฌฌ์•„"
                }
            },
            {
                "_index": "public_chat",
                "_type": "_doc",
                "_id": "edTe0GwBME3K7rKzaiF0",
                "_score": 0.11770796,
                "_source": {
                    "room_name": "๋ง๊ณ "
                }
            },
            {
                "_index": "public_chat",
                "_type": "_doc",
                "_id": "e9Te0GwBME3K7rKzaiF0",
                "_score": 0.101606146,
                "_source": {
                    "room_name": "๋ง๊ณ ๋ง๊ณ ๋ง๊ณ "
                }
            },
            {
                "_index": "public_chat",
                "_type": "_doc",
                "_id": "ftTe0GwBME3K7rKzaiF0",
                "_score": 0.1014327,
                "_source": {
                    "room_name": "๊น€๋ง๊ณ "
                }
            },
            {
                "_index": "public_chat",
                "_type": "_doc",
                "_id": "etTe0GwBME3K7rKzaiF0",
                "_score": 0.08564364,
                "_source": {
                    "room_name": "๋ง๊ณ ์Šคํ‹ด"
                }
            },
            {
                "_index": "public_chat",
                "_type": "_doc",
                "_id": "fdTe0GwBME3K7rKzaiF0",
                "_score": 0.07169379,
                "_source": {
                    "room_name": "๋ง๊ณ ํ›„๋šœ๋ฃน"
                }
            },
            {
                "_index": "public_chat",
                "_type": "_doc",
                "_id": "f9Te0GwBME3K7rKzaiF0",
                "_score": 0.049237844,
                "_source": {
                    "room_name": "์„ธ์ƒ์—์„œ ์ œ์ผ ๋ง›์žˆ๋Š”๊ฑด ๋ง๊ณ ์ง€"
                }
            }
        ]
    }
}

์šฐ๋ฆฌ์˜ ์˜ˆ์ƒ๊ณผ๋Š” ๋ฐ˜๋Œ€๋กœ ๋‹ค๋ฅธ ์ˆœ์œ„๊ฐ€ ์ถœ๋ ฅ๋˜์—ˆ๋‹ค.

 

 

 

ํ•ด๊ฒฐ


์œ„์™€ ๊ฐ™์ด ์šฐ๋ฆฌ์˜ ์˜ˆ์ƒ๊ณผ ๋ฒ—์–ด๋‚œ ๊ฒฐ๊ณผ๊ฐ€ ์ถœ๋ ฅ๋˜๋Š” ์ด์œ ๋Š” ๊ฐ ์ƒค๋“œ ๋ณ„๋กœ ์Šค์ฝ”์–ด๋ง์„ ํ•œ ํ›„ ๊ฒฐ๊ณผ๋ฅผ ์ทจํ•ฉํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

๊ทธ๋ž˜์„œ, ์šฐ๋ฆฌ๋Š” ์ „์ฒด ์ƒค๋“œ ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๋ฅผ ์ทจํ•ฉํ•œ ํ›„ ์Šค์ฝ”์–ด๋ง ํ•  ํ•„์š”๊ฐ€ ์žˆ๋‹ค.

 

POST /_search?search_type=dfs_query_then_fetch
{
	"query": {
		"match": {
			"room_name": "๋ง๊ณ "
		}
	}
}
{
    "took": 17,
    "timed_out": false,
    "_shards": {
        "total": 3,
        "successful": 3,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 7,
            "relation": "eq"
        },
        "max_score": 0.10460657,
        "hits": [
            {
                "_index": "public_chat",
                "_type": "_doc",
                "_id": "edTe0GwBME3K7rKzaiF0",
                "_score": 0.10460657,
                "_source": {
                    "room_name": "๋ง๊ณ "
                }
            },
            {
                "_index": "public_chat",
                "_type": "_doc",
                "_id": "e9Te0GwBME3K7rKzaiF0",
                "_score": 0.092210956,
                "_source": {
                    "room_name": "๋ง๊ณ ๋ง๊ณ ๋ง๊ณ "
                }
            },
            {
                "_index": "public_chat",
                "_type": "_doc",
                "_id": "ftTe0GwBME3K7rKzaiF0",
                "_score": 0.091497645,
                "_source": {
                    "room_name": "๊น€๋ง๊ณ "
                }
            },
            {
                "_index": "public_chat",
                "_type": "_doc",
                "_id": "etTe0GwBME3K7rKzaiF0",
                "_score": 0.0783982,
                "_source": {
                    "room_name": "๋ง๊ณ ์Šคํ‹ด"
                }
            },
            {
                "_index": "public_chat",
                "_type": "_doc",
                "_id": "fdTe0GwBME3K7rKzaiF0",
                "_score": 0.066497825,
                "_source": {
                    "room_name": "๋ง๊ณ ํ›„๋šœ๋ฃน"
                }
            },
            {
                "_index": "public_chat",
                "_type": "_doc",
                "_id": "fNTe0GwBME3K7rKzaiF0",
                "_score": 0.047680173,
                "_source": {
                    "room_name": "๋ง๊ณ ๊ฐ€์ฌฌ์•„์ฌฌ์•„"
                }
            },
            {
                "_index": "public_chat",
                "_type": "_doc",
                "_id": "f9Te0GwBME3K7rKzaiF0",
                "_score": 0.04666439,
                "_source": {
                    "room_name": "์„ธ์ƒ์—์„œ ์ œ์ผ ๋ง›์žˆ๋Š”๊ฑด ๋ง๊ณ ์ง€"
                }
            }
        ]
    }
}

์œ„์™€ ๊ฐ™์ด serach_type์— dfs_query_then_fetch ์˜ต์…˜์„ ์ฃผ๋ฉด ํ•ด๊ฒฐ๋œ๋‹ค.

 

๋‹จ! ์ •ํ™•ํ•œ ๊ฒฐ๊ณผ๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ์ง€๋งŒ ์„ฑ๋Šฅ์ด ๋Š๋ฆฌ๋ฏ€๋กœ ์ƒ์šฉ ์„œ๋น„์Šค์—์„œ๋Š” ๊ถŒ์žฅ๋˜์ง€ ์•Š๋Š”๋‹ค.
์–ด์ฐจํ”ผ, document์˜ ์ˆซ์ž๊ฐ€ ๋งŽ์•„์ง€๋ฉด ์ด ์˜ต์…˜์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š์•„๋„ ์šฐ๋ฆฌ๊ฐ€ ์˜๋„ํ•œ ์ •ํ™•๋„๋กœ ์ˆ˜๋ ดํ•œ๋‹ค.

 

 

 

์ถœ์ฒ˜


https://stackoverflow.com/questions/47740665/inconsistent-scoring-in-elasticsearch
http://jinuland.blogspot.com/2015/10/elasticsearch-search-type.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html#request-body-search-search-type
๋ฐ˜์‘ํ˜•