2015-09-26 77 views
0

我在弹性搜索中的数据有问题,基本上我需要存储拥有以下文档的用户ID,如果我查看意义上的数据我在userID字段上得到一个“坏字符串”错误。ElasticSearch字段显示为错误的字符串,导致搜索时出现错误

怎么回事?

{"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 : "" 
      } 
     } 
     }]}} 

回答

0

好这个问题在数据被创建的方式躺在如果我的样品上方的字段名称中发现缺少周边行情:

{"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并不会阻止您插入无效数据,并且Elastic将简单地将该数据输出到您使用的任何客户端,在PHP下,这将导致JsonExceptionError,因为无效的json不能编码成数组。

另外我在做父/子关系错误,在插入记录时不需要为userID设置字段,只需使用has_parent/filter指定父级和子级查询。