ElasticSearch 字段显示为错误字符串,在搜索时导致错误
ElasticSearch field showing as bad string, causes error when searched
我在 elasticsearch 中遇到数据问题,基本上我需要存储拥有以下文档的用户 ID,如果我在某种意义上查看数据,我可以在除用户 ID 之外的任何内容上进行搜索,我得到 "bad string" userID 字段错误。
这是怎么回事?
{"took":1,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":3,"max_score":1.0,"hits":[{"_index":"pheme","_type":"searches","_id":"AU__X0W7bLxGTuBqZB_E","_score":1.0,"_source":{
userID: "AU__X0W7bLxGTuBqZB_E", **<---- This shows as bad string in Sense**
mustHave: "Laravel",
notHave: "Moogle",
couldHave: "AngularJS",
exclusions: {
ID : ""
}
}
},{"_index":"pheme","_type":"searches","_id":"AU__ZNA0bLxGTuBqZCCn","_score":0.30685282,"_source":{
userID: "AU__X0W7bLxGTuBqZB_E",
mustHave: "Laravel",
notHave: "Moogle",
couldHave: "AngularJS",
exclusions: {
ID : ""
}
}
},{"_index":"pheme","_type":"searches","_id":"AVAJl5OZbMFoS2ut2YM9","_score":0.30685282,"_source":{
userID: "AU__X0W7bLxGTuBqZB_E",
mustHave: "Laravel",
notHave: "Moogle",
couldHave: "AngularJS",
exclusions: {
ID : ""
}
}
}]}}
好的,如果您在上面的示例中注意到字段名称缺少引号,那么问题出在数据的创建方式上:
{"took":1,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":3,"max_score":1.0,"hits":[{"_index":"pheme","_type":"searches","_id":"AU__X0W7bLxGTuBqZB_E","_score":1.0,"_source":{
userID: "AU__X0W7bLxGTuBqZB_E", **<---- This shows as bad string in Sense**
mustHave: "Laravel",
notHave: "Moogle",
couldHave: "AngularJS",
exclusions: {
ID : ""
}
}
}
应该
{"took":1,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":3,"max_score":1.0,"hits":[{"_index":"pheme","_type":"searches","_id":"AU__X0W7bLxGTuBqZB_E","_score":1.0,"_source":{
"userID": "AU__X0W7bLxGTuBqZB_E", **<---- This shows as bad string in Sense**
"mustHave": "Laravel",
"notHave": "Moogle",
"couldHave": "AngularJS",
"exclusions": {
"ID" : ""
}
}
}
请务必注意,Sense under marvel 不会阻止您插入无效数据,Elastic 只会将该数据输出到您使用的任何客户端,在 PHP 下,这将导致 JsonExceptionError,因为无效 json无法编码成数组。
此外,我做错了 parent/child 关系,插入记录时不需要为 userID 设置字段,您只需指定父项,然后使用 has_parent/filter.[=12= 进行查询]
我在 elasticsearch 中遇到数据问题,基本上我需要存储拥有以下文档的用户 ID,如果我在某种意义上查看数据,我可以在除用户 ID 之外的任何内容上进行搜索,我得到 "bad string" userID 字段错误。
这是怎么回事?
{"took":1,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":3,"max_score":1.0,"hits":[{"_index":"pheme","_type":"searches","_id":"AU__X0W7bLxGTuBqZB_E","_score":1.0,"_source":{
userID: "AU__X0W7bLxGTuBqZB_E", **<---- This shows as bad string in Sense**
mustHave: "Laravel",
notHave: "Moogle",
couldHave: "AngularJS",
exclusions: {
ID : ""
}
}
},{"_index":"pheme","_type":"searches","_id":"AU__ZNA0bLxGTuBqZCCn","_score":0.30685282,"_source":{
userID: "AU__X0W7bLxGTuBqZB_E",
mustHave: "Laravel",
notHave: "Moogle",
couldHave: "AngularJS",
exclusions: {
ID : ""
}
}
},{"_index":"pheme","_type":"searches","_id":"AVAJl5OZbMFoS2ut2YM9","_score":0.30685282,"_source":{
userID: "AU__X0W7bLxGTuBqZB_E",
mustHave: "Laravel",
notHave: "Moogle",
couldHave: "AngularJS",
exclusions: {
ID : ""
}
}
}]}}
好的,如果您在上面的示例中注意到字段名称缺少引号,那么问题出在数据的创建方式上:
{"took":1,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":3,"max_score":1.0,"hits":[{"_index":"pheme","_type":"searches","_id":"AU__X0W7bLxGTuBqZB_E","_score":1.0,"_source":{
userID: "AU__X0W7bLxGTuBqZB_E", **<---- This shows as bad string in Sense**
mustHave: "Laravel",
notHave: "Moogle",
couldHave: "AngularJS",
exclusions: {
ID : ""
}
}
}
应该
{"took":1,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":3,"max_score":1.0,"hits":[{"_index":"pheme","_type":"searches","_id":"AU__X0W7bLxGTuBqZB_E","_score":1.0,"_source":{
"userID": "AU__X0W7bLxGTuBqZB_E", **<---- This shows as bad string in Sense**
"mustHave": "Laravel",
"notHave": "Moogle",
"couldHave": "AngularJS",
"exclusions": {
"ID" : ""
}
}
}
请务必注意,Sense under marvel 不会阻止您插入无效数据,Elastic 只会将该数据输出到您使用的任何客户端,在 PHP 下,这将导致 JsonExceptionError,因为无效 json无法编码成数组。
此外,我做错了 parent/child 关系,插入记录时不需要为 userID 设置字段,您只需指定父项,然后使用 has_parent/filter.[=12= 进行查询]