1

假设我的文件是这样的

{
    "salary": {
        "max": 1572,
        "min": 682
    },
    "skills": [
        "Modula-3",
        "Max/MSP",
        "Arduino",
        "SPARK",
        "PL/SQL",
        "Processing",
        "Go",
        "Mathematica",
        "Modula-2",
        "IDL",
        "Heron",
        "Scheme"
    ],
    "company": "Merck",
    "experience": 0,
    "role": "Airport Security Screener",
    "cities": [
        "Ahmedabad",
        "Mangaluru",
        "Malegaon",
        "Bokaro Steel City",
        "Vadodara",
        "Kollam"
    ]
}

我想做一个查询,我将在其中提供一组城市,并根据交集的基数获取文档。即假设我的城市集是["Ahmedabad", "Mangaluru"],那么这个查询与上述文档的交集的基数是 2。我的查询应该是什么?

样本响应

{"_score": 4.0202227, "cities": ["Ahmedabad","Mangaluru","Visakhapatnam", "Vijayawada"]}
{"_score": 2.27, "cities": ["Ahmedabad","Visakhapatnam", "Vijayawada"]}
{"_score": 1.79, "cities": ["Mangalauru","Vijayawada", "delhi", "bombay"]}

我正在使用弹性搜索 5.2.2

4

1 回答 1

0

也许这样的事情会帮助你?

{
  "query": {
    "function_score": {
      "query": {
        "match": {
          "cities": "Ahmedabad Mangaluru"
        }
      },
      "functions": [
        {
          "filter": {
            "match": {
              "cities": "Ahmedabad"
            }
          },
          "weight": 1
        },
        {
          "filter": {
            "match": {
              "cities": "Mangaluru"
            }
          },
          "weight": 1
        }
      ],
      "score_mode": "sum"
    }
  }
}
于 2017-05-10T20:52:56.560 回答