23

したがって、私の問題は基本的にここで説明したものと同じですが、グループではまだ回答がありません。

私のマッピング:

{
    "abstract": {
        "properties": {
            "summary": {
                "type": "string"
            }
        }
    },
    "authors": {
        "type": "nested",
        "properties": {
            "first_name": {
                "type": "string"
            },
            "last_name": {
                 "type": "string"
            }
        }
    }
}

そして、これらのフィールドの両方で全文検索を実行したいと思いますが、おそらく重みが等しくありません。私の頭に浮かんだが、残念ながらうまくいかないクエリは次のとおりです。

{
    "query": {
        "bool": {
            "should": [{
                "multi_match": {
                    "query": "higgs boson",
                    "fields": ["abstract.summary^5", "author.last_name^2"]
                }
            }]
        }
    }
}

ネストされたマッピングのため、authors フィールドから結果が得られません。また、ネストされたプロパティを取り除くこともできません。集計に使用しています。それを解決するエレガントなアイデアはありますか?

4

2 に答える 2

14

The only solution that I managed to work out, which is not handy nor elegant but somehow works is such query:

"query": {
    "bool": {
        "should": [
            {
                "nested": {
                    "path": "authors",
                    "query": {
                        "multi_match": {
                            "query": "higgs",
                            "fields": ["last_name^2"]
                        }
                    }
                } 
            },
            {
                "multi_match": {
                    "query": "higgs",
                    "fields": ["abstract.summary^5"]
                }
            }
        ]
    }
}

I'm also not sure if the boosting will work as expected, providing it's set in different queries. Any suggestions appreciated.

于 2015-08-05T10:25:45.527 に答える
13

マッピングを使用include_in_root: trueする次のものに変更すると、元のクエリを使用できるようになります。

{
    "abstract": {
        "properties": {
            "summary": {
                "type": "string"
            }
        }
    },
    "authors": {
        "type": "nested",
        "include_in_root": true,
        "properties": {
            "first_name": {
                "type": "string"
            },
            "last_name": {
                 "type": "string"
            }
        }
    }
}

ネストされたフィールドとフラット化されたオブジェクト フィールドの両方として、内部オブジェクトにインデックスを付けたい場合があります。これは、include_in_parent を true に設定することで実現できます。-リンク

注:include_in_rootは、elasticsearch の将来のバージョンでは推奨されなくなり、 が優先される可能性がありますcopy_to

于 2016-03-23T13:45:33.220 に答える