gpt4 book ai didi

elasticsearch - Elasticsearch :parse_exception:无法解析搜索源。预期的字段名称,但获得了[START_OBJECT]

转载 作者:行者123 更新时间:2023-12-02 23:28:25 26 4
gpt4 key购买 nike

我是Elastic Search的新手,并且在我的应用程序中使用ES。当我在ES的单个表上运行简单查询时,它就可以工作了。.但是,当我使用嵌套查询时,它并不能给我正确的结果。

基本上,我有两个表peopleinteractions都是单独的表。交互表具有person_id,它引用人员表ID。我想获取具有user_id: 2的人的互动。创建条件并运行查询时,出现错误。

以下是我正在运行的查询。

{
"index": "my_index",
"type": "people",
"fields": "_source,_timestamp",
"size": 10,
"from": 0,
"body": {
"query": {
"bool": {
"should": {
"wildcard": {
"_all": "*a*"
}
}
},
"nested": {
"path": "interactions",
"query": {
"bool": {
"should": {
"match": {
"interactions.user_id": 2
}
}
}
}
}
},
"sort": [
{
"last_name": {
"order": "asc"
}
}
]
}
}

以下是我得到的回应
{
"status": false,
"error_code": 657,
"errors": [
"parse_exception: failed to parse search source. expected field name but got [START_OBJECT]"
]
}

以下是我们在ES中索引的数据


[
{
"id": 1,
"first_name": "Test1",
"last_name": "Data1",
"date_of_birth": "1988-11-02",
"created_at": ".......",
"updated_at": ".......",
"status": 1,
"prefix": "Ms.",
"suffix": "MD"
},
{
"id": 1,
"first_name": "Test2",
"last_name": "Data2",
"date_of_birth": "1988-11-02",
"created_at": ".......",
"updated_at": ".......",
"status": 1,
"prefix": "Ms.",
"suffix": "MD"
}
]

互动
[
{
"id": 1,
"user_id": 11,
"person_id": 6,
"interaction_type": 1,
"initiated_by": 2,
"created_at": ".......",
"updated_at": "......."
},
{
"id": 2,
"user_id": 10,
"person_id": 5,
..........
}
]

有人可以建议我在此查询中我做错了什么吗?
提前致谢。

最佳答案

更新的答案。
试试这个。

{
"fields" : "_source,_timestamp",
"size" : 10,
"from" : 0,
"query" : {
"bool" : {
"should" : [{
"wildcard" : {
"_all" : "*a*"
}
}, {
"nested" : {
"path" : "interactions",
"query" : {
"bool" : {
"should" : {
"match" : {
"interactions.user_id" : 2
}
}
}
}
}
}
]
}
},
"sort" : [{
"last_name" : {
"order" : "asc"
}
}
]
}

您的json格式错误。您在排序中遗漏了']'。试试下面

您可以使用 http://jsonlint.com/这样的网站来验证json。
{
"index": "my_index",
"type": "people",
"fields": "_source,_timestamp",
"size": 10,
"from": 0,
"body": {
"query": {
"bool": {
"should": {
"wildcard": {
"_all": "*a*"
}
}
},
"nested": {
"path": "interactions",
"query": {
"bool": {
"should": {
"match": {
"interactions.user_id": 2
}
}
}
}
}
},
"sort": [{
"last_name": {
"order": "asc"
}
}]
}
}

关于elasticsearch - Elasticsearch :parse_exception:无法解析搜索源。预期的字段名称,但获得了[START_OBJECT],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39806720/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com