0

我在elasticsearch中的数据有问题,基本上我需要存储拥有以下文档的用户ID,如果我查看数据,我可以搜索除用户ID之外的任何内容,我在用户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 : ""
      }
    }
    },{"_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 : ""
          }
        }
        }]}}
4

1 回答 1

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

请务必注意,Marvel 下的 Sense 不会阻止您插入无效数据,并且 Elastic 只会将该数据输出到您使用的任何客户端,在 PHP 下这将导致 JsonExceptionError,因为无法将无效的 json 编码到数组中。

另外我做错了父/子关系,插入记录时不需要用户ID字段,您只需指定父级然后使用has_parent/filter查询。

于 2015-09-26T20:30:09.663 回答