Search code examples
elasticsearchgeolocation

How to use dot notation in geo percolator


I use Elasticsearch 2.2.1 for searching documents that relate to a specific geo graphic location (within a bouding box). I want to create a percolator that I can use to check if a new document relates to an existing query.

This works fine if I put the percolator into the index containing the documents but because of the issue mention in this document and the workaround mentioned here I need to put the percolate queries into a dedicated percolator index.

When I try to put a percolator into this index:

PUT /mypercindex/.percolator/1
  {"query": {"filtered": {"filter":
    {"bool":
        {"should":
            [
                {"geo_bounding_box":
                    {"location.coordinates":
                        {"bottom_right":
                            {"lat":50.0,"lon":8.0}
                        ,"top_left":
                            {"lat":54.0,"lon":3.0}
                        }
                    }
                }
            ]
        }
    }
}}}

I get an error message saying that:

Strict field resolution and no field mapping can be found for the field with name [location.coordinates]

In the percolator documentation is mentioned that, in case of a dedicated percolator index, you need to:

make sure that the mappings from the normal index are also available on the percolate index

This may cause my issue but I cannot find the documentation about how to make the mapping from one index available in the other. I tried to add the dedicated percolator index with the same mapping as my document index but when I do this I still get the same error message.

The mapping of my document index resembles this:

{"my_mapping": {
  "dynamic":"strict",
  "properties":{
    "body":{
        "properties":{
            "author":{
                "type":"string",
                "index":"not_analyzed"
            },
            "hashtags":{
                "type":"string",
                "index":"not_analyzed"
            },
            "language":{
                "type":"string",
                "index":"not_analyzed"
            }
            ,"text":{
                "type":"string",
                "analyzer":"stopwords"
            },
            "title":{
                "type":"string",
                "analyzer":"stopwords"
            }
        }
    },
    "location":{
        "properties":{
            "coordinates":{
                "type":"geo_point"
            },
            "names":{
                "type":"string",
                "analyzer":"standard"
            }
        }
    }
  }
}}

Any help would be greatly appreciated!


Solution

  • Adding a .percolator mapping to the mapping, like mentioned in the Github issue that addresses this workaround, fixed the issue for me:

    ".percolator": {
      "dynamic": true,
      "properties": {
        "id": {
          "type": "integer"
        }
      }
    }