我无法弄清楚为什么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添加了应该匹配的文档 –