elasticsearch查询中的文档重复

rnmwe5a2  于 2021-06-14  发布在  ElasticSearch
关注(0)|答案(0)|浏览(317)

我不熟悉elasticsearch。我需要动态地构建查询,其中对于每个字段名,获取相应的文件
我有下面的问题,谁能说这是正确的方法?同样在这个查询中,文档只是重复一个特定的文件名
请告诉我怎么办

GET index_name/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "bool": {
            "must": [
              {
                "match_phrase": {
                  "field_name": "program"
                }
              },
              {
                "match_phrase": {
                  "field_value": "aaa-123"
                }
              }
            ]
          }
        },
        {
          "bool": {
            "must": [
              {
                "match_phrase": {
                  "field_name": "species"
                }
              },
              {
                "match_phrase": {
                  "field_value": "mouse"
                }
              }
            ]
          }
        },
        {
          "bool": {
            "must": [
              {
                "match_phrase": {
                  "field_name": "model name"
                }
              },
              {
                "match_phrase": {
                  "field_value": "b45"
                }
              }
            ]
          }
        }
      ]
    }
  },"aggs": {
    "2": {
      "terms": {
        "field": "myfile_file_name.keyword",
        "size": 1000,
        "order": {
          "_key": "asc"
        }
      },
      "aggs": {
        "3": {
          "terms": {
            "field": "field_name.keyword",
            "size": 1000,
            "order": {
              "_key": "asc"
            }
          }
        }
      }
    }
  }
}

Map和输出

{
       "_index" : "test",
       "_type" : "test_data",
       "_id" : "123",
       "_score" : 1.0,
       "_source" : {
         "document_id" : 123,
         "m_id" : 1,
         "source" : "ADDD",
         "type" : "M",
         "name" : "Animal",
         "value" : "None",
         "test_type" : "Test123",
         "file_name" : "AA.zip",
         "description" : "testing",
         "program" : ["hello"],
         "species" : ["mouse"],
         "study" : ["Study1"],
         "create_date" : "2020-08-20 11:51:21.152",
         "update_date" : "2020-08-20 11:51:21.152",
         "source_name" : "Anim",
         "auth" : ["na"],
         "treatment" : ["TR001", "TR002", "TR004"],
         "timepoint" : ["72", "48"],
         "findings_reports" : "na",
         "model" : ["None",],
         "additional" : "{'view': '', 'load': []}",
         "data" : "Pre"
       }
     },
   ]
 }
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题