0
インデックスには、locations
のプロパティが "入れ子になっています"というマッピングがあります。このプロパティには場所の配列が含まれます。ネストされたプロパティ内に指定されたオブジェクトのANYを持つ文書をElasticsearchで選択します。
{
"id": string,
"type": string
}
私のウェブサイト上で、私は複数の場所を選択して、私が選択したこれらの場所のANYを持っているすべての文書を検索する:それぞれの場所には、次のような構造を持つオブジェクトです。私は1つの場所で検索することができましたが、何とか多くの場所を検索するためにクエリを変更する必要があります。
私は、次のインデックスが設定されている:
"mappings": {
"users": {
"properties": {
"locations": {
"type": "nested",
"properties": {
"id": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"type": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"id": {
"type": "long"
}
}
}
}
例の文書:
{
"locations": [
{
"id": "UA",
"type": "country"
},
{
"id": "RU",
"type": "country"
},
{
"id": "OC",
"type": "continent"
}
]
}
場所でユーザーを検索する
マイクエリ:
{
"query": {
"bool": {
"must": [
{
"nested": {
"path": "locations",
"query": {
"bool": {
"must": [
{
"match": { "locations.id": "RU" }
},
{
"match": { "locations.type": "country" }
}
]
}
}
}
}
]
}
}
}
EDIT: 私はまた、ドキュメンタリーを検索したいlocations.type
がcontinent
に等しい。 SQLでは、複数の値検索の使用Termsために、使用するshould
(hereを参照)OR条件
WHERE (id IN ('UA', 'RU') AND type = 'country')
OR (id IN ('EU', 'OC', 'NA') AND type = 'continent')
はおかげで、私もlocations.typeを持つ文書を盗んしたいです「大陸」に等しい。 SQLでは、 'WHERE(ID IN( 'UA'、 'RU')AND type = 'country')のように見えるでしょう。OR(id IN( 'EU'、 'OC'、 'NA')AND type = 'continent' ) '私はそれをどのように達成できますか? – starky
私の回答を更新します – Eli
ありがとう!それがまさに私が必要としていたものです。 – starky