【问题标题】:elasticsearch nested query with ruby gem使用 ruby​​ gem 的 elasticsearch 嵌套查询
【发布时间】:2014-06-05 16:11:18
【问题描述】:

我正在使用 elasticsearch ruby​​ gem 连接到一个 es 服务器,并且目前有一个具有以下映射的索引。我试图了解查询这些嵌套对象的正确语法。尝试如下查询,但不断出错。我想知道是否有人可以让我开始使用正确的语法来查询这样的结构?谢谢!

client = Elasticsearch::Client.new log:true

client.search index: 'injuries', nested: { path: { week: {id: '1' } } }

返回:

Elasticsearch::Transport::Transport::Errors::BadRequest: [400] {"error":"SearchPhaseExecutionException[Failed to execute phase [query

示例映射:

{
  "injuries" : {
    "mappings" : {
      "tbd" : {
        "properties" : {
          "injuries" : {
             "properties" : {
               "timestamp" : {
                 "properties" : {
                   "__content__" : {
                    "type" : "string"
                  },
                   "timeZone" : {
                    "type" : "string"
                  }
                }
              }
            }
          }
        }
      },
      "football" : {
        "properties" : {
          "injuries" : {
            "properties" : {
              "timestamp" : {
                "properties" : {
                  "__content__" : {
                    "type" : "string"
                  },
                  "timeZone" : {
                    "type" : "string"
                  }
                }
              },
              "week" : {
                "properties" : {
                  "id" : {
                    "type" : "string"
                  },
                   "inactivePlayers" : {
                    "properties" : {
                      "inactivePlayer" : {
                        "properties" : {
                          "firstName" : {
                            "type" : "string"
                          },
                          "lastName" : {
                            "type" : "string"
                          },
                          "playerId" : {
                            "type" : "string"
                          },
                          "position" : {
                            "type" : "string"
                          },
                          "status" : {
                            "type" : "string"
                          },
                          "teamId" : {
                            "type" : "string"
                          }
                        }
                      }
                    }
                  },
                  "injuredPlayers" : {
                    "properties" : {
                      "injuredPlayer" : {
                        "properties" : {
                          "displayName" : {
                            "type" : "string"
                          },
                          "firstName" : {
                            "type" : "string"
                          },
                          "gameStatus" : {
                            "type" : "string"
                          },
                          "injury" : {
                            "type" : "string"
                          },
                          "lastName" : {
                             "type" : "string"
                          },
                          "playerId" : {
                            "type" : "string"
                          },
                          "position" : {
                             "type" : "string"
                           },
                           "practiceStatus" : {
                             "type" : "string"
                          },
                          "teamId" : {
                             "type" : "string"
                           }
                        }
                      }
                   }
                  },
                  "season" : {
                     "type" : "string"
                  },
                  "seasonType" : {
                     "type" : "string"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

【问题讨论】:

    标签: ruby lucene elasticsearch


    【解决方案1】:

    您的nested query 似乎没有定义query。我认为应该是这样的:

    "nested" : {
        "path" : "week",
        "query" : {
            "match" : {"week.id" : "1"}
         }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-08
      • 2018-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多