Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
<img src="//i.stack.imgur.com/RUiNP.png" height="16" width="18" alt="" class="sponsor tag img">elasticsearch 如何通过elasticsearch搜索嵌套过滤器_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch 如何通过elasticsearch搜索嵌套过滤器,elasticsearch,elasticsearch" /> elasticsearch 如何通过elasticsearch搜索嵌套过滤器,elasticsearch,elasticsearch" />

elasticsearch 如何通过elasticsearch搜索嵌套过滤器

elasticsearch 如何通过elasticsearch搜索嵌套过滤器,elasticsearch,elasticsearch,我想使用[nested filter]函数。 因为,我只想对嵌套数据进行筛选 例如,如果ElasticSearch具有此数据。 我想得到它。但我尝试使用[nested filter],无法获取此数据。 你知道好的解决方案吗 实际上,我想在嵌套类型中有2个条件。 这就像sql, 在document_comments.document_id=document.id上选择*from document internal Join,其中document_comments.deleted_at为null,d

我想使用[nested filter]函数。 因为,我只想对嵌套数据进行筛选

例如,如果ElasticSearch具有此数据。 我想得到它。但我尝试使用[nested filter],无法获取此数据。 你知道好的解决方案吗

实际上,我想在嵌套类型中有2个条件。 这就像sql, 在document_comments.document_id=document.id上选择*from document internal Join,其中document_comments.deleted_at为null,document_comments.comment类似“test”

[数据]

"_source": {
"id": 4,
"name": "hogehoge.csv",
"deleted_at": null,
"hard_delete": null,
"document_comments": [
{
"id": 8,
"comment": "test",
"document_id": 4,
"deleted_at": "2016-03-03T13:43:10"
}
,
{
"id": 11,
"comment": "test",
"document_id": 4,
"deleted_at": null
}
]
}
[制图]

 "documents": {
"search_analyzer": "default_search",
"dynamic_templates": [
  {
    "string_template": {
      "mapping": {
        "type": "multi_field",
        "fields": {
          "ja": {
            "analyzer": "ja_analyzer",
            "index": "analyzed",
            "type": "string"
          },
          "{name}": {
            "analyzer": "ngram_analyzer",
            "index": "analyzed",
            "type": "string"
          },
          "yomi": {
            "analyzer": "yomi_analyzer",
            "index": "analyzed",
            "type": "string"
          },
          "full": {
            "index": "not_analyzed",
            "type": "string"
          }
        }
      },
      "match_mapping_type": "string",
      "match": "*"
    }
  }
],
"properties": {
  "@timestamp": {
    "format": "dateOptionalTime",
    "type": "date"
  },
  "document_comments": {
    "type": "nested",
    "properties": {
      "deleted_at": {
        "format": "dateOptionalTime",
        "type": "date"
      },
      "document_id": {
        "type": "integer"
      },
      "comment": {
        "index": "no",
        "type": "string",
        "fields": {
          "ja": {
            "analyzer": "ja_analyzer",
            "type": "string"
          },
          "yomi": {
            "analyzer": "yomi_analyzer",
            "type": "string"
          },
          "ngram": {
            "analyzer": "ngram_analyzer",
            "type": "string"
          },
          "full": {
            "index": "not_analyzed",
            "type": "string"
          }
        }
      },
      "id": {
        "type": "long"
      },
      "deleted_at": {
        "format": "dateOptionalTime",
        "type": "date"
      }
    }
  },
  "name": {
    "index": "no",
    "type": "string",
    "fields": {
      "ja": {
        "analyzer": "ja_analyzer",
        "type": "string"
      },
      "yomi": {
        "analyzer": "yomi_analyzer",
        "type": "string"
      },
      "ngram": {
        "analyzer": "ngram_analyzer",
        "type": "string"
      },
      "full": {
        "index": "not_analyzed",
        "type": "string"
      }
    }
  },
  "delete_at": {
    "format": "dateOptionalTime",
    "type": "date"
  },
  "id": {
    "type": "integer"
  },
  "hard_delete": {
    "format": "dateOptionalTime",
    "type": "date"
  }
}
}

[查询]

{
  "_source": [
    "id",
    "deleted_at",
    "document_comments.comment",
    "document_comments.deleted_at"
  ],
  "min_score": 0.05,
  "query": {
    "filtered": {
      "query": {
        "bool": {
          "must": [],
          "should": [
            {
              "multi_match": {
                "query": "test",
                "type": "cross_fields",
                "fields": [
                  "document.name.ja"
                ]
              }
            },
            {
              "nested": {
                "path": "document_comments",
                "query": {
                  "bool": {
                    "must": [
                      {
                        "multi_match": {
                          "query": "test",
                          "type": "cross_fields",
                          "fields": [
                            "document_comments.comment.ja"
                          ]
                        }
                      }
                    ],
                    "must_not": [
                      {
                        "filter": {
                          "exists": {
                            "field": "document_comments.deleted_at"
                          }
                        }
                      }
                    ]
                  }
                }
              }
            }
          ]
        }
      },
      "filter": {
        "bool": {
          "must": [
            [
              {
                "missing": {
                  "field": "deleted_at",
                  "existence": "true",
                  "null_value": "true"
                }
              },
              {
                "missing": {
                  "field": "hard_delete",
                  "existence": "true",
                  "null_value": "true"
                }
              }
            ],
            {
              "type": {
                "value": "document"
              }
            },
            {
              "term": {
                "id": "3"
              }
            }
          ]
        }
      }
    }
  },
  "sort": [
    {
      "id": "desc"
    },
    {
      "_score": "asc"
    }
  ]
}