正在寻找帮助我使用 ElasticSearch 的人

Looking for someone to help me with ElasticSearch

我是 ElasticSearch 的初学者。我正在尝试测试地理点列表(纬度/经度)是否存在于地理点列表中。

例如我给这个地理点:

"lat": 49.01536940596998
"lon": 2.4967825412750244

而且我想测试一下这个点是否存在于下面的列表中。谢谢

"positions": [
    {
      "millis": 12959023,
      "lat": 49.01525113731623,
      "lon": 2.4971945118159056,
      "rawX": -3754,
      "rawY": 605,
      "rawVx": 0,
      "rawVy": 0,
      "speed": 9.801029291617944,
      "accel": 0.09442740907572084,
      "grounded": true
    },
    {
      "millis": 12959914,
      "lat": 49.01536940596998,
      "lon": 2.4967825412750244,
      "rawX": -3784,
      "rawY": 619,
      "rawVx": -15,
      "rawVy": 7,
      "speed": 10.841861737855924,
      "accel": -0.09534648619563282,
      "grounded": true
    }
...
}

为了能够在对象数组中进行搜索,您需要使用 nested data type。正如链接页面所解释的那样,要使数组的内部元素保持独立,您不能使用默认映射。首先,您必须更新映射。

注意:映射只对新索引生效。 Reference.

PUT YOUR_INDEX
{
  "mappings": {
    "YOUR_TYPE": {
      "properties": {
        "positions": {
          "type": "nested" 
        }
      }
    }
  }
}

现在我们可以查询数据了。您正在寻找 bool query, which combines other queries (in your case, term queries).

POST _search
{
  "query": {
    "nested": {
      "path": "positions",
      "query": {
        "bool" : {
          "must" : [
            { "term" : { "lat": 49.01536940596998  } },
            { "term" : { "lon": 2.4967825412750244 } }
          ]
        }
      }
    }
  }
}