Im, мигрирующий из Tire в Flex Основные операции поиска и индексирования Я понял, что линия flex.parent в модели автоматически создаст сопоставление _parent, но оно сработает Мне не удалось найти родительскую/дочернюю демонстрацию проект.Как создать отображение родительского ребенка?
Flex.yml:
settings:
number_of_shards: 5
number_of_replicas: 1
# analysis:
# analyzer:
# tokenizer:
mappings:
userprofile:
startdatef:
type: 'date'
format: 'dateOptionalTime'
fields:
index: 'not_analyzed'
untouched:
type: 'date'
index: 'not_analyzed'
orgunit:
org_name:
type: 'string'
index: 'analyzed'
search_analyzer: orgunit_name_search
index_analyzer: orgunit_name_index
untouched:
type: 'string'
index: 'not_analyzed'
Родитель модель:
class Userprofile < ActiveRecord::Base
include Flex::ModelIndexer
include Flex::Model
flex.sync self
has_many :assignments,
-> { order(startdate: :desc) }, dependent: :restrict_with_exception
module Search
include Flex::Scopes
flex.context = Userprofile
scope :alla, query([])
end
# rubocop:disable all
def flex_source
{
id: id,
fullname: fullname,
firstname: firstname,
lastname: lastname,
pnr: pnr,
gender: gender,
asscount: asscount,
created_at: created_at,
updated_at: updated_at,
user_id: user_id,
creator_id: creator_id,
}
end
# rubocop:enable all
end
Ребенок модель:
class Assignment < ActiveRecord::Base
include Flex::ModelIndexer
include Flex::Model
flex.parent :userprofile, 'userprofile' => 'assignment' # This makes indexing break
flex.sync self, :userprofile
belongs_to :userprofile, counter_cache: true, touch: true
module Search
include Flex::Scopes
flex.context = Assignment
scope :alla, query([])
end
def flex_source
{
# _parent_id: userprofile_id,
userprofile_id: userprofile_id,
created_at: created_at,
updated_at: updated_at
}
end
end
грабли прогибается: импорт
Модель Userprofile: обработка 37 документов партиями 1000: обработка ...: 100% ||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||| Время: 0:00:01 Обработанные 37. Успешное 37. Пропущенные 0. Failed 0.
Модель Назначение: Обработка 36 документов в партиях от 1000: рейка прервана !: 0% | | ETA: -: -: - ActiveRecord-4.0.2/Библиотека/active_record/отношение/batches.rb: 75: в find_in_batches' 400: {"error":"ElasticSearchIllegalArgumentException[Can't specify parent if no parent field has been configured]","status":400} flex-1.0.6/lib/flex/template.rb:54:in
do_render» ... Задачи: TOP => прогибается: импорт
Я не смог использовать точный код, и он сказал мне, что я не смог обновить родительское сопоставление. Но я понял, что нужно, и, кажется, я получил это работает с рубином flex.yml: отображения: Назначение: _parent: Тип: 'профиль_пользователя' Assignment.rb: flex.parent: профиль_пользователя, 'профиль_пользователь' => 'назначение' flex.sync самость,: профиль_пользователь flex_search.yml: амбар: - запрос: has_child: Тип: назначение запрос: термин: pg_id: <> –
user2957461
Рад слышать, что это вам помогло. Тогда вы можете принять ответ. – dr0i
о, я немного новый, нашел его :) – user2957461