normal(not nested)
mapping
curl -X PUT "es:9200/sample1" -H 'Content-Type: application/json' -d'
{
"mappings": {
"_doc": {
"properties": {
"header" : {
"type" : "text"
},
"body" : {
"type" : "text"
}
}
}
}
}
'
register
curl -X PUT "es:9200/sample1/_doc/1?refresh" -H 'Content-Type: application/json' -d'
{
"header": "最適な問題",
"body": "これは数学です。"
}
'
curl -X PUT "es:9200/sample1/_doc/2?refresh" -H 'Content-Type: application/json' -d'
{
"header": "最悪な回答",
"body": "これは社会です。"
}
'
curl -X PUT "es:9200/sample1/_doc/3?refresh" -H 'Content-Type: application/json' -d'
{
"header": "最良の問題",
"body": "これは国語です。"
}
'
curl -X PUT "es:9200/sample1/_doc/4?refresh" -H 'Content-Type: application/json' -d'
{
"header": "ひどい回答",
"body": "これは理科です。"
}
'
search query
curl -XGET 'es:9200/sample1/_search?pretty' -H 'Content-Type: application/json' -d'
{
"query" : {
"simple_query_string":{
"query": "最適",
"fields": ["header","body"]
}
}
}'
result
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 3,
"max_score" : 0.6931472,
"hits" : [
{
"_index" : "sample1",
"_type" : "_doc",
"_id" : "2",
"_score" : 0.6931472,
"_source" : {
"header" : "最悪な回答",
"body" : "これは社会です。"
}
},
{
"_index" : "sample1",
"_type" : "_doc",
"_id" : "1",
"_score" : 0.5753642,
"_source" : {
"header" : "最適な問題",
"body" : "これは数学です。"
}
},
{
"_index" : "sample1",
"_type" : "_doc",
"_id" : "3",
"_score" : 0.2876821,
"_source" : {
"header" : "最良の問題",
"body" : "これは国語です。"
}
}
]
}
}
nested
mapping
curl -X PUT "es:9200/sample2" -H 'Content-Type: application/json' -d'
{
"mappings": {
"_doc": {
"properties": {
"title" : {
"type" : "text"
},
"contents": {
"type": "nested"
}
}
}
}
}
'
register
curl -X PUT "es:9200/sample2/_doc/1?refresh" -H 'Content-Type: application/json' -d'
{
"title": "Test title",
"contents": [
{
"header": "最適な問題",
"body": "これは数学です。"
},
{
"header": "最悪な回答",
"body": "これは社会です。"
}
]
}
'
curl -X PUT "es:9200/sample2/_doc/2?refresh" -H 'Content-Type: application/json' -d'
{
"title": "Test title",
"contents": [
{
"header": "最良の問題",
"body": "これは国語です。"
},
{
"header": "ひどい回答",
"body": "これは理科です。"
}
]
}
'
search query
curl -XGET "es:9200/sample2/_search?pretty" -H 'Content-Type: application/json' -d'
{
"_source": false,
"size": 20,
"query": {
"nested": {
"path": "contents",
"score_mode": "max",
"query" : {
"simple_query_string":{
"query": "最適",
"fields": ["contents.header","contents.body"],
"auto_generate_synonyms_phrase_query": 'true'
}
},
"inner_hits": {}
}
}
}
'
result
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 0.87546873,
"hits" : [
{
"_index" : "sample2",
"_type" : "_doc",
"_id" : "1",
"_score" : 0.87546873,
"inner_hits" : {
"contents" : {
"hits" : {
"total" : 2,
"max_score" : 0.87546873,
"hits" : [
{
"_index" : "sample2",
"_type" : "_doc",
"_id" : "1",
"_nested" : {
"field" : "contents",
"offset" : 0
},
"_score" : 0.87546873,
"_source" : {
"header" : "最適な問題",
"body" : "これは数学です。"
}
},
{
"_index" : "sample2",
"_type" : "_doc",
"_id" : "1",
"_nested" : {
"field" : "contents",
"offset" : 1
},
"_score" : 0.18232156,
"_source" : {
"header" : "最悪な回答",
"body" : "これは社会です。"
}
}
]
}
}
}
},
{
"_index" : "sample2",
"_type" : "_doc",
"_id" : "2",
"_score" : 0.6931472,
"inner_hits" : {
"contents" : {
"hits" : {
"total" : 1,
"max_score" : 0.6931472,
"hits" : [
{
"_index" : "sample2",
"_type" : "_doc",
"_id" : "2",
"_nested" : {
"field" : "contents",
"offset" : 0
},
"_score" : 0.6931472,
"_source" : {
"header" : "最良の問題",
"body" : "これは国語です。"
}
}
]
}
}
}
}
]
}
}
↑のresultを比べてみると、
該当した同じテキストに対するスコアリングや、それに伴い、順番が違っています。
なぜ同じスコアリングや、順番にならないのでしょうか?
inner_hitsでの検索と、そうでない検索は、検索ロジックが全く別のものを使っているということでしょうか?