우리는 탄성 검색 (ES)에 관한 두 가지 유형의 문서, 즉 항목 및 슬롯 (항목은 슬롯 문서의 부모)을 사용합니다.elasitcsearch 부모 자식 문서 쿼리
curl -XPOST 'localhost:9200/items/slot/_mapping' -d @slotsdef.json
: itemsdef.json
그런 다음 다음과 같은 정의
{
"mappings" : {
"item" : {
"properties" : {
"id" : {"type" : "long" },
"name" : {
"type" : "string",
"_analyzer" : "textIndexAnalyzer"
},
"location" : {"type" : "geo_point" },
}
}
},
"settings" : {
"analysis" : {
"analyzer" : {
"activityIndexAnalyzer" : {
"alias" : ["activityQueryAnalyzer"],
"type" : "custom",
"tokenizer" : "whitespace",
"filter" : ["trim", "lowercase", "asciifolding", "spanish_stop", "spanish_synonym"]
},
"textIndexAnalyzer" : {
"type" : "custom",
"tokenizer" : "whitespace",
"filter" : ["word_delimiter_impl", "trim", "lowercase", "asciifolding", "spanish_stop", "spanish_synonym"]
},
"textQueryAnalyzer" : {
"type" : "custom",
"tokenizer" : "whitespace",
"filter" : ["trim", "lowercase", "asciifolding", "spanish_stop"]
}
},
"filter" : {
"spanish_stop" : {
"type" : "stop",
"ignore_case" : true,
"enable_position_increments" : true,
"stopwords_path" : "analysis/spanish-stopwords.txt"
},
"spanish_synonym" : {
"type" : "synonym",
"synonyms_path" : "analysis/spanish-synonyms.txt"
},
"word_delimiter_impl" : {
"type" : "word_delimiter",
"generate_word_parts" : true,
"generate_number_parts" : true,
"catenate_words" : true,
"catenate_numbers" : true,
"split_on_case_change" : false
}
}
}
}
}
을 가지고 우리는 다음과 같은 명령을 사용하여 자식 문서 정의를 추가
curl -XPOST 'localhost:9200/items' -d @itemsdef.json
: 우리는 다음 명령을 사용하여 인덱스를 정의 slotsdef.json
의 정의는 다음과 같습니다.
{
"slot" : {
"_parent" : {"type" : "item"},
"_routing" : {
"required" : true,
"path" : "parent_id"
},
"properties": {
"id" : { "type" : "long" },
"parent_id" : { "type" : "long" },
"activity" : {
"type" : "string",
"_analyzer" : "activityIndexAnalyzer"
},
"day" : { "type" : "integer" },
"start" : { "type" : "integer" },
"end" : { "type" : "integer" }
}
}
}
마지막으로 우리는 다음과 같은 명령으로 대량 지수를 수행
curl -XPOST 'localhost:9200/items/_bulk' --data-binary @testbulk.json
testbulk.json 다음 데이터 보유
: 나는 다음과 같은 쿼리를 만들려고
{"index":{"_type": "item", "_id":35}}
{"location":[40.4,-3.6],"id":35,"name":"A Name"}
{"index":{"_type":"slot","_id":126,"_parent":35}}
{"id":126,"start":1330,"day":1,"end":1730,"activity":"An Activity","parent_id":35}
을 : 검색 지정된 일 및 특정 시작 및 끝 범위 내에서 하위 (슬롯)가있는 위치까지의 특정 거리 내의 모든 항목에 대해
조건을 충족하는 슬롯이 더 많은 항목의 점수가 높아야합니다.
기존 샘플부터 시작했지만 문서는 실제로 부족하고 앞으로 나아갈 수 없습니다.
단서?
어느 정도의 비정규 화 적용은 어떻게됩니까? 어쩌면 검색 가능한 모든 부모 특성을 자식으로 이동하고 부모를 자식을 그룹화하는 구조로 남겨 둘 수 있습니다. 중첩 된 문서가 더 적합할까요? –
그래, 내가 대답의 시작 부분에 언급 한대로 슬롯에 도움이 될 수도 있습니다. 합리적인 성능을 얻었는지 확인하기 위해 몇 가지 테스트를 수행 한 다음 비정규 화 후에 이러한 테스트를 반복하는 것이 좋습니다. – imotov