在查询elasticsearch中访问字段文档
Access field document in query elasticsearch
例如假设我们有这个映射:
{
"location":{
"dynamic":"false",
"properties":{
"locality":{"type":"text"},
"country":{"type":"text"},
"postalCode":{"type":"text"},
"coordinates":{"type":"geo_point"},
"radius":{"type":"double"}
}
}
}
这是我的查询:
GET index_name/location/_search
{
"query": {
"bool": {
"filter": {
"geo_distance": {
"coordinates": [
2.352222,
48.999
],
"distance": $radius <--- *(here I want to access the
value of radius in document)*
}
}
}
}
}
有没有办法在 Elasticsearch 查询中访问字段文档值?
使用脚本查询是否可行?文档 here
是的,实际上 脚本查询 可以解决问题:
GET index_name/location/_search
{
"query": {
"bool": {
"must": [
{
"script": {
"script": {
"inline": "doc['coordinates'].planeDistance(48.856614 , 2.37959999) <= doc['radius'].value",
"lang": "painless"
}
}
}
]
}
}
}
感谢
例如假设我们有这个映射:
{
"location":{
"dynamic":"false",
"properties":{
"locality":{"type":"text"},
"country":{"type":"text"},
"postalCode":{"type":"text"},
"coordinates":{"type":"geo_point"},
"radius":{"type":"double"}
}
}
}
这是我的查询:
GET index_name/location/_search
{
"query": {
"bool": {
"filter": {
"geo_distance": {
"coordinates": [
2.352222,
48.999
],
"distance": $radius <--- *(here I want to access the
value of radius in document)*
}
}
}
}
}
有没有办法在 Elasticsearch 查询中访问字段文档值?
使用脚本查询是否可行?文档 here
是的,实际上 脚本查询 可以解决问题:
GET index_name/location/_search
{
"query": {
"bool": {
"must": [
{
"script": {
"script": {
"inline": "doc['coordinates'].planeDistance(48.856614 , 2.37959999) <= doc['radius'].value",
"lang": "painless"
}
}
}
]
}
}
}
感谢