我無法弄清楚爲什麼elasticsearch不用not_analysed索引進行搜索。我在我的模型中有以下設置,Elasticsearch不處理「not_analyzed」索引
settings index: { number_of_shards: 1 } do
mappings dynamic: 'false' do
indexes :id
indexes :name, index: 'not_analyzed'
indexes :email, index: 'not_analyzed'
indexes :contact_number
end
end
def as_indexed_json(options = {})
as_json(only: [ :id, :name, :username, :user_type, :is_verified, :email, :contact_number ])
end
而我在elasticsearch的映射是正確的,如下所示。
{
"users-development" : {
"mappings" : {
"user" : {
"dynamic" : "false",
"properties" : {
"contact_number" : {
"type" : "string"
},
"email" : {
"type" : "string",
"index" : "not_analyzed"
},
"id" : {
"type" : "string"
},
"name" : {
"type" : "string",
"index" : "not_analyzed"
}
}
}
}
}
}
但問題是,當我就沒有分析領域的搜索(姓名和電子郵件,因爲我希望他們可以不分析),它只能在完整的單詞進行搜索。就像在下面的例子中,它應該有約翰,約翰和虎的所有3條記錄。但它只返回2條記錄。
我正在尋找如下
settings = {
query: {
filtered: {
filter: {
bool: {
must: [
{ terms: { name: [ "john", "tiger" ] } },
]
}
}
}
},
size: 10
}
User.__elasticsearch__.search(settings).records
這是我如何在回調after_save
創建我的用戶對象上的索引,
User.__elasticsearch__.client.indices.create(
index: User.index_name,
id: self.id,
body: self.as_indexed_json,
)
一些應符合
[{
"_index" : "users-development",
"_type" : "user",
"_id" : "670",
"_score" : 1.0,
"_source":{"id":670,"email":"[email protected]","name":"john baba","contact_number":null}
},
{
"_index" : "users-development",
"_type" : "user",
"_id" : "671",
"_score" : 1.0,
"_source":{"id":671,"email":"hu[email protected]","name":"Johny Rocket","contact_number":null}
}
, {
"_index" : "users-development",
"_type" : "user",
"_id" : "736",
"_score" : 1.0,
"_source":{"id":736,"email":"[email protected]","name":"tiger sherof", "contact_number":null}
} ]
文檔
請提出任何建議。
以上查詢中的user_type是什麼? – Richa
你是如何編制索引的? 「約翰」還是「約翰」?你能告訴我們你認爲應該匹配的文件嗎? – ChintanShah25
@ ChintanShah25添加了應該匹配的文檔 –