0
색인에서 locations
유형의 "중첩 된"특성을 포함하는 매핑이 있습니다. 이 속성에는 위치 배열이 포함되어 있습니다.내포 된 속성 내에 제공된 객체가 모두있는 Elasticsearch에서 문서를 선택하십시오.
{
"id": string,
"type": string
}
내 웹 사이트에 여러 지역을 선택하고 내가 선택한이 위치의 어떤있는 모든 문서를 찾으려면 각 위치는 다음과 같은 구조의 개체입니다. 한 위치에서 검색 할 수 있었지만 여러 위치를 검색하기 위해 어떻게 든 내 쿼리를 수정해야합니다.
나는 다음과 같은 지수가 설정 한 :
"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" }
}
]
}
}
}
}
]
}
}
}
편집 : 나는 또한 docum을 탐구하고 싶다. 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이 문서를 retreive 할 '대륙'과 동등하다. SQL에서는 'WHERE (id IN ('UA ','RU ') AND type ='country ') OR (id IN ('EU ','OC ','NA ') AND type ='continent ')'어떻게 할 수 있습니까? – starky
내 대답을 업데이트하겠습니다 – Eli
고마워요! 그게 내가 필요한 것입니다. – starky