Elasticsearch,如何在特定结构上使用filter gte

时间:2015-10-09 14:53:26

标签: elasticsearch

我正在尝试学习Elasticsearch,因此我试图找到一个符合我查询需求的良好数据结构。

我的数据结构实际上是这样的:

ifstream  inpFile;
ofstream outFile;

/* I receive the files' names via argv, some are input some are output
 * (order is fixed but not the number)
 * /.prog outpu1 input1 output2 input2 (and so on)
 * degenerated example on how It works:
 *    for(int i=argc-1; i>0; i-=2){
 *       inpFile.open(argv[i]);
 *       if(inpFile.is_open()) return true;
 *    }
 */
if (!initFiles (argc, argv, inpFile, outFile))
    return 1;

istream &inStream = (inpFile.is_open()) ? inpFile : cin;
ostream &outStream = (outFile.is_open()) ? outFile : cout;

对于给定的患者,有多个问题和答案。 有没有办法利用Elasticsearch过滤的查询并说: { "questions": [ { "id": "n1-pain-score", "name": "Pain score", "answer": { "value": 3, "label": "Small pain" } }, { "id": "n2-temperature", "name": "Temperature", "answer": { "value": 37.5, "label": "37.5°C" } } ] }

请注意,我只是测试,我仍然可以修改数据结构以获得我想要的:)。

1 个答案:

答案 0 :(得分:0)

可以使用筛选查询。一个普通的查询也可以:

GET {index}/{type}/_search
{
    "query": {
        "bool": {
            "must": [
               {
                   "match": {
                      "name": "Pain score"
                   }
               },
               {
                 "range": {
                    "answer.value": {
                      "gt":6
                    }
                 }
               }
            ]
        }
    }
}