【问题标题】:Elastic Search not returning matched data弹性搜索不返回匹配的数据
【发布时间】:2017-10-11 07:13:23
【问题描述】:

我有一个弹性搜索索引,映射如下:

{
  "issues": {
    "mappings": {
      "issues": {
        "properties": {
          "captured_by": {
            "type": "long"
          },
          "captured_on": {
            "type": "date",
            "format": "dateOptionalTime"
          },
          "description": {
            "type": "string"
          },
          "id": {
            "type": "string",
            "index": "not_analyzed"
          },
          "updated_at": {
            "type": "date",
            "format": "dateOptionalTime"
          }
          "issue_org_states": {
            "type": "nested",
            "properties": {
              "assigned_at": {
                "type": "date",
                "format": "dateOptionalTime"
              },
              "assigned_by": {
                "type": "long"
              },
              "updated_at": {
                "type": "date",
                "format": "dateOptionalTime"
              },
              "updated_by": {
                "type": "long"
              }
            }
          }
        }
      }
    }
  }
}

并填充一个文档如下:

{
  "took": 2,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 1,
    "hits": [
      {
        "_index": "issues",
        "_type": "issues",
        "_id": "13f3bf09-08cb-4464-b326-15872bdb0870",
        "_score": 1,
        "_source": {
          "id": "13f3bf09-08cb-4464-b326-15872bdb0870",
          "description": "Sloppy paint job",
          "captured_on": "2017-10-09T09:24:01.928Z",
          "captured_by": 1,
          "updated_at": "2017-10-09T12:47:22.982Z",
          "issue_org_states": [
            {
              "updated_at": "2017-10-09T12:47:22.982Z",
              "updated_by": 1,
              "assigned_at": "2017-10-09T12:47:22.982Z",
              "assigned_by": 1879048240
            }
          ]
        }
      }
    ]
  }
}

我想查询属性assigned_at 和updated_at 上的路径“issues.issue_org_states”。 查询如下:

{
  "query": {
    "nested": {
      "path": "issue_org_states",
      "range": {
        "assigned_at": {
          "from": "2017-10-09T00:00:00.000Z",
          "to": "2017-10-09T23:59:59.999Z",
          "include_lower": true,
          "include_upper": true
        }
      }
    }
  }
}

当我在上面运行时查询它的返回数据。但是,如果在 updated_at 而不是 assignment_at 上运行相同的查询,则弹性搜索返回 0 结果。 assign_at 和 updated_at 都具有相同的映射和相同的数据,直到下面的查询不返回任何结果。

    {
  "query": {
    "nested": {
      "path": "issue_org_states",
      "range": {
        "updated_at": {
          "from": "2017-10-09T00:00:00.000Z",
          "to": "2017-10-09T23:59:59.999Z",
          "include_lower": true,
          "include_upper": true
        }
      }
    }
  }
}

如果我在这里遗漏了什么,请帮忙。

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    elasticsearch 5.4.0 上测试并针对 issue_org_states.updated_atissue_org_states.assigned_at 进行查询可以正常工作。您可能想再次查看您的实际命令行。

    我的查询如下,基于this document

    curl -XGET -u elastic:changeme localhost:9200/issues/issues/_search?pretty -d '{
      "query": {
        "nested": {
          "path": "issue_org_states",
          "query" : {
            "range": {
              "issue_org_states.updated_at": {
                "gte": "2017-10-09T00:00:00.000Z",
                "le": "2017-10-09T23:59:59.999Z"
              }
            }
          }
        }
      }
    }'
    
    
    curl -XGET -u elastic:changeme localhost:9200/issues/issues/_search?pretty -d '{
      "query": {
        "nested": {
          "path": "issue_org_states",
          "query" : {
            "range": {
              "issue_org_states.assigned_at": {
                "gte": "2017-10-09T00:00:00.000Z",
                "le": "2017-10-09T23:59:59.999Z"
              }
            }
          }
        }
      }
    }'
    

    映射定义,

    curl -XPUT -u elastic:changeme localhost:9200/issues -d '{
        "mappings": {
          "issues": {
            "properties": {
              "captured_by": {
                "type": "long"
              },
              "captured_on": {
                "type": "date",
                "format": "dateOptionalTime"
              },
              "description": {
                "type": "string"
              },
              "id": {
                "type": "string",
                "index": "not_analyzed"
              },
              "updated_at": {
                "type": "date",
                "format": "dateOptionalTime"
              },
              "issue_org_states": {
                "type": "nested",
                "properties": {
                  "assigned_at": {
                    "type": "date",
                    "format": "dateOptionalTime"
                  },
                  "assigned_by": {
                    "type": "long"
                  },
                  "updated_at": {
                    "type": "date",
                    "format": "dateOptionalTime"
                  },
                  "updated_by": {
                    "type": "long"
                  }
                }
              }
            }
          }
        }
    }'
    

    和你一样的数据。

    curl -XPOST -u elastic:changeme localhost:9200/issues/issues -d '{
    "id": "13f3bf09-08cb-4464-b326-15872bdb0870",
    "description": "Sloppy paint job",
    "captured_on": "2017-10-09T09:24:01.928Z",
    "captured_by": 1,
    "updated_at": "2017-10-09T12:47:22.982Z",
    "issue_org_states": [
                {
                  "updated_at": "2017-10-09T12:47:22.982Z",
                  "updated_by": 1,
                  "assigned_at": "2017-10-09T12:47:22.982Z",
                  "assigned_by": 1879048240
                }
    ]
    }'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多