2015-09-26 32 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指定父級和子級查詢。