Uploaded image for project: 'Couchbase Server'
  1. Couchbase Server
  2. MB-53702

FTS geospatial search: querying indexed polygons with 1 point + contains relation returns weird results

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Not a Bug
    • 7.1.2
    • None
    • fts
    • None
    • Untriaged
    • 1
    • Unknown

    Description

      Testing internally geospatial search on indexes geoshapes (polygons) (which is a new feature implemented starting on 7.1.2), I observe weird results while querying 1 given point:

       

      curl -s -XPOST -H "Content-Type: application/json" -u Administrator:password http://localhost:8094/api/index/polygon_search/query -d '
      {
        "explain": true,
        "fields": [
          "*"
        ],
        "highlight": {},
        "sort": ["-_score"],
        "query": {
          "field": "geometry",
          "geometry": {
            "shape": {
              "type": "Point",
              "coordinates": [
                1.5,
                48.2
              ]
            },
            "relation": "contains"
          }
        }
      }
      '

       

      Result is:

       

       

      {
        "status": {
          "total": 1,
          "failed": 0,
          "successful": 1
        },
        "request": {
          "query": {
            "geometry": {
              "shape": {
                "type": "Point",
                "coordinates": [
                  1.5,
                  48.2
                ]
              },
              "relation": "contains"
            },
            "field": "geometry"
          },
          "size": 10,
          "from": 0,
          "highlight": {
            "style": null,
            "fields": null
          },
          "fields": [
            "*"
          ],
          "facets": null,
          "explain": true,
          "sort": [
            "-score"
          ],
          "includeLocations": false,
          "search_after": null,
          "search_before": null
        },
        "hits": [
          {
            "index": "polygon_search_539a3888dc543770_4c1c5584",
            "id": "commune:71016:Gergy",
            "score": 0.00021008565303260566,
            "explanation": {
              "value": 0.00021008565303260566,
              "message": "product of:",
              "children": [
                {
                  "value": 0.003151284795489085,
                  "message": "sum of:",
                  "children": [
                    {
                      "value": 0.003151284795489085,
                      "message": "weight(geometry:47^1.000000 in \u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000), product of:",
                      "children": [
                        {
                          "value": 0.031052115870816743,
                          "message": "queryWeight(geometry:47^1.000000), product of:",
                          "children": [
                            {
                              "value": 1,
                              "message": "boost"
                            },
                            {
                              "value": 0.9994988724525545,
                              "message": "idf(docFreq=1995, maxDocs=1995)"
                            },
                            {
                              "value": 0.031067684743477052,
                              "message": "queryNorm"
                            }
                          ]
                        },
                        {
                          "value": 0.10148373813234128,
                          "message": "fieldWeight(geometry:47 in \u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000), product of:",
                          "children": [
                            {
                              "value": 1,
                              "message": "tf(termFreq(geometry:47)=1"
                            },
                            {
                              "value": 0.10153461992740631,
                              "message": "fieldNorm(field=geometry, doc=\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000)"
                            },
                            {
                              "value": 0.9994988724525545,
                              "message": "idf(docFreq=1995, maxDocs=1995)"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "value": 0.06666666666666667,
                  "message": "coord(1/15)"
                }
              ]
            },
            "sort": [
              "\u0000"
            ],
            "fields": {
              "properties.code": "71016",
              "properties.nom": "Gergy"
            }
          },
          {
            "index": "polygon_search_539a3888dc543770_4c1c5584",
            "id": "commune:44014:Nantes-4",
            "score": 0.00021008565303260566,
            "explanation": {
              "value": 0.00021008565303260566,
              "message": "product of:",
              "children": [
                {
                  "value": 0.003151284795489085,
                  "message": "sum of:",
                  "children": [
                    {
                      "value": 0.003151284795489085,
                      "message": "weight(geometry:47^1.000000 in \u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0001), product of:",
                      "children": [
                        {
                          "value": 0.031052115870816743,
                          "message": "queryWeight(geometry:47^1.000000), product of:",
                          "children": [
                            {
                              "value": 1,
                              "message": "boost"
                            },
                            {
                              "value": 0.9994988724525545,
                              "message": "idf(docFreq=1995, maxDocs=1995)"
                            },
                            {
                              "value": 0.031067684743477052,
                              "message": "queryNorm"
                            }
                          ]
                        },
                        {
                          "value": 0.10148373813234128,
                          "message": "fieldWeight(geometry:47 in \u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0001), product of:",
                          "children": [
                            {
                              "value": 1,
                              "message": "tf(termFreq(geometry:47)=1"
                            },
                            {
                              "value": 0.10153461992740631,
                              "message": "fieldNorm(field=geometry, doc=\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0001)"
                            },
                            {
                              "value": 0.9994988724525545,
                              "message": "idf(docFreq=1995, maxDocs=1995)"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "value": 0.06666666666666667,
                  "message": "coord(1/15)"
                }
              ]
            },
            "sort": [
              "\u0000"
            ],
            "fields": {
              "properties.code": "44014",
              "properties.nom": "Nantes-4"
            }
          },
          {
            "index": "polygon_search_539a3888dc543770_4c1c5584",
            "id": "commune:90009:Valdoie",
            "score": 0.00021008565303260566,
            "explanation": {
              "value": 0.00021008565303260566,
              "message": "product of:",
              "children": [
                {
                  "value": 0.003151284795489085,
                  "message": "sum of:",
                  "children": [
                    {
                      "value": 0.003151284795489085,
                      "message": "weight(geometry:47^1.000000 in \u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0002), product of:",
                      "children": [
                        {
                          "value": 0.031052115870816743,
                          "message": "queryWeight(geometry:47^1.000000), product of:",
                          "children": [
                            {
                              "value": 1,
                              "message": "boost"
                            },
                            {
                              "value": 0.9994988724525545,
                              "message": "idf(docFreq=1995, maxDocs=1995)"
                            },
                            {
                              "value": 0.031067684743477052,
                              "message": "queryNorm"
                            }
                          ]
                        },
                        {
                          "value": 0.10148373813234128,
                          "message": "fieldWeight(geometry:47 in \u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0002), product of:",
                          "children": [
                            {
                              "value": 1,
                              "message": "tf(termFreq(geometry:47)=1"
                            },
                            {
                              "value": 0.10153461992740631,
                              "message": "fieldNorm(field=geometry, doc=\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0002)"
                            },
                            {
                              "value": 0.9994988724525545,
                              "message": "idf(docFreq=1995, maxDocs=1995)"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "value": 0.06666666666666667,
                  "message": "coord(1/15)"
                }
              ]
            },
            "sort": [
              "\u0000"
            ],
            "fields": {
              "properties.code": "90009",
              "properties.nom": "Valdoie"
            }
          },
          {
            "index": "polygon_search_539a3888dc543770_4c1c5584",
            "id": "commune:93005:Bobigny",
            "score": 0.00021008565303260566,
            "explanation": {
              "value": 0.00021008565303260566,
              "message": "product of:",
              "children": [
                {
                  "value": 0.003151284795489085,
                  "message": "sum of:",
                  "children": [
                    {
                      "value": 0.003151284795489085,
                      "message": "weight(geometry:47^1.000000 in \u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0003), product of:",
                      "children": [
                        {
                          "value": 0.031052115870816743,
                          "message": "queryWeight(geometry:47^1.000000), product of:",
                          "children": [
                            {
                              "value": 1,
                              "message": "boost"
                            },
                            {
                              "value": 0.9994988724525545,
                              "message": "idf(docFreq=1995, maxDocs=1995)"
                            },
                            {
                              "value": 0.031067684743477052,
                              "message": "queryNorm"
                            }
                          ]
                        },
                        {
                          "value": 0.10148373813234128,
                          "message": "fieldWeight(geometry:47 in \u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0003), product of:",
                          "children": [
                            {
                              "value": 1,
                              "message": "tf(termFreq(geometry:47)=1"
                            },
                            {
                              "value": 0.10153461992740631,
                              "message": "fieldNorm(field=geometry, doc=\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0003)"
                            },
                            {
                              "value": 0.9994988724525545,
                              "message": "idf(docFreq=1995, maxDocs=1995)"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "value": 0.06666666666666667,
                  "message": "coord(1/15)"
                }
              ]
            },
            "sort": [
              "\u0000"
            ],
            "fields": {
              "properties.code": "93005",
              "properties.nom": "Bobigny"
            }
          },
          {
            "index": "polygon_search_539a3888dc543770_4c1c5584",
            "id": "commune:76008:Dieppe-2",
            "score": 0.00021008565303260566,
            "explanation": {
              "value": 0.00021008565303260566,
              "message": "product of:",
              "children": [
                {
                  "value": 0.003151284795489085,
                  "message": "sum of:",
                  "children": [
                    {
                      "value": 0.003151284795489085,
                      "message": "weight(geometry:47^1.000000 in \u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0004), product of:",
                      "children": [
                        {
                          "value": 0.031052115870816743,
                          "message": "queryWeight(geometry:47^1.000000), product of:",
                          "children": [
                            {
                              "value": 1,
                              "message": "boost"
                            },
                            {
                              "value": 0.9994988724525545,
                              "message": "idf(docFreq=1995, maxDocs=1995)"
                            },
                            {
                              "value": 0.031067684743477052,
                              "message": "queryNorm"
                            }
                          ]
                        },
                        {
                          "value": 0.10148373813234128,
                          "message": "fieldWeight(geometry:47 in \u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0004), product of:",
                          "children": [
                            {
                              "value": 1,
                              "message": "tf(termFreq(geometry:47)=1"
                            },
                            {
                              "value": 0.10153461992740631,
                              "message": "fieldNorm(field=geometry, doc=\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0004)"
                            },
                            {
                              "value": 0.9994988724525545,
                              "message": "idf(docFreq=1995, maxDocs=1995)"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "value": 0.06666666666666667,
                  "message": "coord(1/15)"
                }
              ]
            },
            "sort": [
              "\u0000"
            ],
            "fields": {
              "properties.code": "76008",
              "properties.nom": "Dieppe-2"
            }
          },
          {
            "index": "polygon_search_539a3888dc543770_4c1c5584",
            "id": "commune:52009:Joinville",
            "score": 0.00021008565303260566,
            "explanation": {
              "value": 0.00021008565303260566,
              "message": "product of:",
              "children": [
                {
                  "value": 0.003151284795489085,
                  "message": "sum of:",
                  "children": [
                    {
                      "value": 0.003151284795489085,
                      "message": "weight(geometry:47^1.000000 in \u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0005), product of:",
                      "children": [
                        {
                          "value": 0.031052115870816743,
                          "message": "queryWeight(geometry:47^1.000000), product of:",
                          "children": [
                            {
                              "value": 1,
                              "message": "boost"
                            },
                            {
                              "value": 0.9994988724525545,
                              "message": "idf(docFreq=1995, maxDocs=1995)"
                            },
                            {
                              "value": 0.031067684743477052,
                              "message": "queryNorm"
                            }
                          ]
                        },
                        {
                          "value": 0.10148373813234128,
                          "message": "fieldWeight(geometry:47 in \u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0005), product of:",
                          "children": [
                            {
                              "value": 1,
                              "message": "tf(termFreq(geometry:47)=1"
                            },
                            {
                              "value": 0.10153461992740631,
                              "message": "fieldNorm(field=geometry, doc=\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0005)"
                            },
                            {
                              "value": 0.9994988724525545,
                              "message": "idf(docFreq=1995, maxDocs=1995)"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "value": 0.06666666666666667,
                  "message": "coord(1/15)"
                }
              ]
            },
            "sort": [
              "\u0000"
            ],
            "fields": {
              "properties.code": "52009",
              "properties.nom": "Joinville"
            }
          },
          {
            "index": "polygon_search_539a3888dc543770_4c1c5584",
            "id": "commune:51008:Épernay-2",
            "score": 0.00021008565303260566,
            "explanation": {
              "value": 0.00021008565303260566,
              "message": "product of:",
              "children": [
                {
                  "value": 0.003151284795489085,
                  "message": "sum of:",
                  "children": [
                    {
                      "value": 0.003151284795489085,
                      "message": "weight(geometry:47^1.000000 in \u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0006), product of:",
                      "children": [
                        {
                          "value": 0.031052115870816743,
                          "message": "queryWeight(geometry:47^1.000000), product of:",
                          "children": [
                            {
                              "value": 1,
                              "message": "boost"
                            },
                            {
                              "value": 0.9994988724525545,
                              "message": "idf(docFreq=1995, maxDocs=1995)"
                            },
                            {
                              "value": 0.031067684743477052,
                              "message": "queryNorm"
                            }
                          ]
                        },
                        {
                          "value": 0.10148373813234128,
                          "message": "fieldWeight(geometry:47 in \u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0006), product of:",
                          "children": [
                            {
                              "value": 1,
                              "message": "tf(termFreq(geometry:47)=1"
                            },
                            {
                              "value": 0.10153461992740631,
                              "message": "fieldNorm(field=geometry, doc=\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0006)"
                            },
                            {
                              "value": 0.9994988724525545,
                              "message": "idf(docFreq=1995, maxDocs=1995)"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "value": 0.06666666666666667,
                  "message": "coord(1/15)"
                }
              ]
            },
            "sort": [
              "\u0000"
            ],
            "fields": {
              "properties.code": "51008",
              "properties.nom": "Épernay-2"
            }
          },
          {
            "index": "polygon_search_539a3888dc543770_4c1c5584",
            "id": "commune:35023:Rennes-6",
            "score": 0.00021008565303260566,
            "explanation": {
              "value": 0.00021008565303260566,
              "message": "product of:",
              "children": [
                {
                  "value": 0.003151284795489085,
                  "message": "sum of:",
                  "children": [
                    {
                      "value": 0.003151284795489085,
                      "message": "weight(geometry:47^1.000000 in \u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0007), product of:",
                      "children": [
                        {
                          "value": 0.031052115870816743,
                          "message": "queryWeight(geometry:47^1.000000), product of:",
                          "children": [
                            {
                              "value": 1,
                              "message": "boost"
                            },
                            {
                              "value": 0.9994988724525545,
                              "message": "idf(docFreq=1995, maxDocs=1995)"
                            },
                            {
                              "value": 0.031067684743477052,
                              "message": "queryNorm"
                            }
                          ]
                        },
                        {
                          "value": 0.10148373813234128,
                          "message": "fieldWeight(geometry:47 in \u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0007), product of:",
                          "children": [
                            {
                              "value": 1,
                              "message": "tf(termFreq(geometry:47)=1"
                            },
                            {
                              "value": 0.10153461992740631,
                              "message": "fieldNorm(field=geometry, doc=\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0007)"
                            },
                            {
                              "value": 0.9994988724525545,
                              "message": "idf(docFreq=1995, maxDocs=1995)"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "value": 0.06666666666666667,
                  "message": "coord(1/15)"
                }
              ]
            },
            "sort": [
              "\u0000"
            ],
            "fields": {
              "properties.code": "35023",
              "properties.nom": "Rennes-6"
            }
          },
          {
            "index": "polygon_search_539a3888dc543770_4c1c5584",
            "id": "commune:29026:Saint-Pol-de-Léon",
            "score": 0.00021008565303260566,
            "explanation": {
              "value": 0.00021008565303260566,
              "message": "product of:",
              "children": [
                {
                  "value": 0.003151284795489085,
                  "message": "sum of:",
                  "children": [
                    {
                      "value": 0.003151284795489085,
                      "message": "weight(geometry:47^1.000000 in \u0000\u0000\u0000\u0000\u0000\u0000\u0000\b), product of:",
                      "children": [
                        {
                          "value": 0.031052115870816743,
                          "message": "queryWeight(geometry:47^1.000000), product of:",
                          "children": [
                            {
                              "value": 1,
                              "message": "boost"
                            },
                            {
                              "value": 0.9994988724525545,
                              "message": "idf(docFreq=1995, maxDocs=1995)"
                            },
                            {
                              "value": 0.031067684743477052,
                              "message": "queryNorm"
                            }
                          ]
                        },
                        {
                          "value": 0.10148373813234128,
                          "message": "fieldWeight(geometry:47 in \u0000\u0000\u0000\u0000\u0000\u0000\u0000\b), product of:",
                          "children": [
                            {
                              "value": 1,
                              "message": "tf(termFreq(geometry:47)=1"
                            },
                            {
                              "value": 0.10153461992740631,
                              "message": "fieldNorm(field=geometry, doc=\u0000\u0000\u0000\u0000\u0000\u0000\u0000\b)"
                            },
                            {
                              "value": 0.9994988724525545,
                              "message": "idf(docFreq=1995, maxDocs=1995)"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "value": 0.06666666666666667,
                  "message": "coord(1/15)"
                }
              ]
            },
            "sort": [
              "\u0000"
            ],
            "fields": {
              "properties.code": "29026",
              "properties.nom": "Saint-Pol-de-Léon"
            }
          },
          {
            "index": "polygon_search_539a3888dc543770_4c1c5584",
            "id": "commune:22026:Trégueux",
            "score": 0.00021008565303260566,
            "explanation": {
              "value": 0.00021008565303260566,
              "message": "product of:",
              "children": [
                {
                  "value": 0.003151284795489085,
                  "message": "sum of:",
                  "children": [
                    {
                      "value": 0.003151284795489085,
                      "message": "weight(geometry:47^1.000000 in \u0000\u0000\u0000\u0000\u0000\u0000\u0000\t), product of:",
                      "children": [
                        {
                          "value": 0.031052115870816743,
                          "message": "queryWeight(geometry:47^1.000000), product of:",
                          "children": [
                            {
                              "value": 1,
                              "message": "boost"
                            },
                            {
                              "value": 0.9994988724525545,
                              "message": "idf(docFreq=1995, maxDocs=1995)"
                            },
                            {
                              "value": 0.031067684743477052,
                              "message": "queryNorm"
                            }
                          ]
                        },
                        {
                          "value": 0.10148373813234128,
                          "message": "fieldWeight(geometry:47 in \u0000\u0000\u0000\u0000\u0000\u0000\u0000\t), product of:",
                          "children": [
                            {
                              "value": 1,
                              "message": "tf(termFreq(geometry:47)=1"
                            },
                            {
                              "value": 0.10153461992740631,
                              "message": "fieldNorm(field=geometry, doc=\u0000\u0000\u0000\u0000\u0000\u0000\u0000\t)"
                            },
                            {
                              "value": 0.9994988724525545,
                              "message": "idf(docFreq=1995, maxDocs=1995)"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "value": 0.06666666666666667,
                  "message": "coord(1/15)"
                }
              ]
            },
            "sort": [
              "\u0000"
            ],
            "fields": {
              "properties.code": "22026",
              "properties.nom": "Trégueux"
            }
          }
        ],
        "total_hits": 1994,
        "max_score": 0.00021008565303260566,
        "took": 100542557,
        "facets": null
      }

       

       

      First county "Gergy" (id = commune:71016:Gergy) does not contain point (lon,lat) (1.5,48.2):

       

       

      {
        "type": "Feature",
        "geometry": {
          "type": "Polygon",
          "coordinates": [
            [
              [
                4.8089,
                46.9307
              ],
              [
                4.8534,
                46.9458
              ],
              [
                4.8937,
                46.951
              ],
              [
                4.8943,
                46.9663
              ],
              [
                4.9479,
                46.9664
              ],
              [
                4.9852,
                46.9585
              ],
              [
                5.0034,
                46.9722
              ],
              [
                5.0493,
                46.9817
              ],
              [
                5.0731,
                46.9668
              ],
              [
                5.0729,
                46.9604
              ],
              [
                5.1086,
                46.9596
              ],
              [
                5.1213,
                46.9634
              ],
              [
                5.1663,
                46.9638
              ],
              [
                5.1961,
                46.9783
              ],
              [
                5.2117,
                46.98
              ],
              [
                5.2078,
                46.9722
              ],
              [
                5.228,
                46.9505
              ],
              [
                5.2338,
                46.9316
              ],
              [
                5.2168,
                46.926
              ],
              [
                5.2223,
                46.9175
              ],
              [
                5.2039,
                46.9129
              ],
              [
                5.1882,
                46.9251
              ],
              [
                5.1582,
                46.926
              ],
              [
                5.1485,
                46.9165
              ],
              [
                5.1525,
                46.9012
              ],
              [
                5.138,
                46.8843
              ],
              [
                5.1533,
                46.873
              ],
              [
                5.1415,
                46.8589
              ],
              [
                5.1433,
                46.8463
              ],
              [
                5.1259,
                46.8395
              ],
              [
                5.1149,
                46.8435
              ],
              [
                5.0955,
                46.8411
              ],
              [
                5.0656,
                46.8434
              ],
              [
                5.0357,
                46.8207
              ],
              [
                5.0201,
                46.821
              ],
              [
                4.9577,
                46.8053
              ],
              [
                4.9535,
                46.8254
              ],
              [
                4.9081,
                46.7969
              ],
              [
                4.8986,
                46.8122
              ],
              [
                4.9067,
                46.8179
              ],
              [
                4.9014,
                46.8318
              ],
              [
                4.8837,
                46.8485
              ],
              [
                4.8909,
                46.8519
              ],
              [
                4.8753,
                46.8774
              ],
              [
                4.8576,
                46.8769
              ],
              [
                4.8574,
                46.8621
              ],
              [
                4.8506,
                46.8509
              ],
              [
                4.8305,
                46.8531
              ],
              [
                4.8252,
                46.8647
              ],
              [
                4.8149,
                46.886
              ],
              [
                4.8223,
                46.8915
              ],
              [
                4.8089,
                46.9307
              ]
            ]
          ]
        },
        "properties": {
          "code": "71016",
          "nom": "Gergy"
        }
      } 

       

       

      So it should not be returned in the results list. Other results are not good (spread across France with no "contains" logic respected).

      For all results, I also notice the score is very low: is it a problem of sorting data (DESC) ? How to do it (I tried using in the sort array parameter "-_score" and also  "-score" but with no success)?

       

      I put in attachment:

      • French counties (communes_simplifiees.json file) pushed into CB bucket using this command line:

      /cbimport json -c couchbase://localhost -u Administrator -p password -b poc_renault -d file:///opt/couchbase/bin/communes_simplifiees.json -t 2 --format list --generate-key commune:%properties.code%:%properties.nom%

      * current FTS index definition

       

      Thanks in advance.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          abhinav Abhi Dangeti added a comment -

          Fabrice Leray seems to me your observation is accurate.

          It seems while we're doing a polygon-contains-point query we're getting inverted results!

          Let's say I indexed 2 docs ..

          1. {"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[4.8089,46.9307],[4.8534,46.9458],[4.8937,46.951],[4.8943,46.9663],[4.9479,46.9664],[4.9852,46.9585],[5.0034,46.9722],[5.0493,46.9817],[5.0731,46.9668],[5.0729,46.9604],[5.1086,46.9596],[5.1213,46.9634],[5.1663,46.9638],[5.1961,46.9783],[5.2117,46.98],[5.2078,46.9722],[5.228,46.9505],[5.2338,46.9316],[5.2168,46.926],[5.2223,46.9175],[5.2039,46.9129],[5.1882,46.9251],[5.1582,46.926],[5.1485,46.9165],[5.1525,46.9012],[5.138,46.8843],[5.1533,46.873],[5.1415,46.8589],[5.1433,46.8463],[5.1259,46.8395],[5.1149,46.8435],[5.0955,46.8411],[5.0656,46.8434],[5.0357,46.8207],[5.0201,46.821],[4.9577,46.8053],[4.9535,46.8254],[4.9081,46.7969],[4.8986,46.8122],[4.9067,46.8179],[4.9014,46.8318],[4.8837,46.8485],[4.8909,46.8519],[4.8753,46.8774],[4.8576,46.8769],[4.8574,46.8621],[4.8506,46.8509],[4.8305,46.8531],[4.8252,46.8647],[4.8149,46.886],[4.8223,46.8915],[4.8089,46.9307]]]},"properties":{"code":"71016","nom":"Gergy"}} 

          1. {"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[2.2266,48.7816],[2.2348,48.7954],[2.255,48.8101],[2.2518,48.8164],[2.2726,48.8144],[2.2894,48.8283],[2.3013,48.8251],[2.2799,48.8109],[2.2717,48.7905],[2.2288,48.7745],[2.2266,48.7761],[2.2266,48.7816]]]},"properties":{"code":"92008","nom":"Clamart"}} 

          The index mapping just indexes the "geometry" field as a `geoshape` type.

          When I search for a point that occurs in the first polygon above, I get the second document as a hit ..

          {"query": {"field": "geometry", "geometry":{"shape":{"type":"point","coordinates":[5, 46.9]},"relation":"contains"}}} 

          And as seen in the description above, search for a document that occurs in neither of the documents' polygons, I get both documents as hits ..

          {"query": {"field": "geometry", "geometry":{"shape":{"type":"point","coordinates":[1.5, 48.2]},"relation":"contains"}}} 

          Wrapping the above queries within the must_not clause yields the expected results.

          Sreekanth Sivasankaran Am I missing something obvious here or is this a legit bug?

          Here's a PR with a unit test reproducing the situation: https://github.com/blevesearch/bleve/pull/1730

          abhinav Abhi Dangeti added a comment - Fabrice Leray seems to me your observation is accurate. It seems while we're doing a polygon-contains-point query we're getting inverted results ! Let's say I indexed 2 docs .. { "type" : "Feature" , "geometry" :{ "type" : "Polygon" , "coordinates" :[[[ 4.8089 , 46.9307 ],[ 4.8534 , 46.9458 ],[ 4.8937 , 46.951 ],[ 4.8943 , 46.9663 ],[ 4.9479 , 46.9664 ],[ 4.9852 , 46.9585 ],[ 5.0034 , 46.9722 ],[ 5.0493 , 46.9817 ],[ 5.0731 , 46.9668 ],[ 5.0729 , 46.9604 ],[ 5.1086 , 46.9596 ],[ 5.1213 , 46.9634 ],[ 5.1663 , 46.9638 ],[ 5.1961 , 46.9783 ],[ 5.2117 , 46.98 ],[ 5.2078 , 46.9722 ],[ 5.228 , 46.9505 ],[ 5.2338 , 46.9316 ],[ 5.2168 , 46.926 ],[ 5.2223 , 46.9175 ],[ 5.2039 , 46.9129 ],[ 5.1882 , 46.9251 ],[ 5.1582 , 46.926 ],[ 5.1485 , 46.9165 ],[ 5.1525 , 46.9012 ],[ 5.138 , 46.8843 ],[ 5.1533 , 46.873 ],[ 5.1415 , 46.8589 ],[ 5.1433 , 46.8463 ],[ 5.1259 , 46.8395 ],[ 5.1149 , 46.8435 ],[ 5.0955 , 46.8411 ],[ 5.0656 , 46.8434 ],[ 5.0357 , 46.8207 ],[ 5.0201 , 46.821 ],[ 4.9577 , 46.8053 ],[ 4.9535 , 46.8254 ],[ 4.9081 , 46.7969 ],[ 4.8986 , 46.8122 ],[ 4.9067 , 46.8179 ],[ 4.9014 , 46.8318 ],[ 4.8837 , 46.8485 ],[ 4.8909 , 46.8519 ],[ 4.8753 , 46.8774 ],[ 4.8576 , 46.8769 ],[ 4.8574 , 46.8621 ],[ 4.8506 , 46.8509 ],[ 4.8305 , 46.8531 ],[ 4.8252 , 46.8647 ],[ 4.8149 , 46.886 ],[ 4.8223 , 46.8915 ],[ 4.8089 , 46.9307 ]]]}, "properties" :{ "code" : "71016" , "nom" : "Gergy" }} { "type" : "Feature" , "geometry" :{ "type" : "Polygon" , "coordinates" :[[[ 2.2266 , 48.7816 ],[ 2.2348 , 48.7954 ],[ 2.255 , 48.8101 ],[ 2.2518 , 48.8164 ],[ 2.2726 , 48.8144 ],[ 2.2894 , 48.8283 ],[ 2.3013 , 48.8251 ],[ 2.2799 , 48.8109 ],[ 2.2717 , 48.7905 ],[ 2.2288 , 48.7745 ],[ 2.2266 , 48.7761 ],[ 2.2266 , 48.7816 ]]]}, "properties" :{ "code" : "92008" , "nom" : "Clamart" }} The index mapping just indexes the "geometry" field as a `geoshape` type. When I search for a point that occurs in the first polygon above, I get the second document as a hit .. { "query" : { "field" : "geometry" , "geometry" :{ "shape" :{ "type" : "point" , "coordinates" :[ 5 , 46.9 ]}, "relation" : "contains" }}} And as seen in the description above, search for a document that occurs in neither of the documents' polygons, I get both documents as hits .. { "query" : { "field" : "geometry" , "geometry" :{ "shape" :{ "type" : "point" , "coordinates" :[ 1.5 , 48.2 ]}, "relation" : "contains" }}} Wrapping the above queries within the must_not clause yields the expected results. Sreekanth Sivasankaran Am I missing something obvious here or is this a legit bug? Here's a PR with a unit test reproducing the situation: https://github.com/blevesearch/bleve/pull/1730
          Sreekanth Sivasankaran Sreekanth Sivasankaran added a comment - - edited

          Fabrice Leray , Abhi Dangeti , this polygon isn't following the FTS-supported anti-clockwise ordering of vertices. And hence the weird results. Counter Clock Wise ordering (CCW) is the recommended ordering of the vertices as per GeoJSON standard.

          You can verify the sanity of the geojson shapes using online tools like - https://geojsonlint.com/

          So, this is working as expected 

           

          Sreekanth Sivasankaran Sreekanth Sivasankaran added a comment - - edited Fabrice Leray , Abhi Dangeti , this polygon isn't following the FTS-supported anti-clockwise ordering of vertices. And hence the weird results. Counter Clock Wise ordering (CCW) is the recommended ordering of the vertices as per GeoJSON standard. You can verify the sanity of the geojson shapes using online tools like - https://geojsonlint.com/ So, this is working as expected   
          aditi.ahuja Aditi Ahuja added a comment -

          This is the GeoJSON spec for polygons, just FYI - https://www.rfc-editor.org/rfc/rfc7946.html#section-3.1.6 

          aditi.ahuja Aditi Ahuja added a comment - This is the GeoJSON spec for polygons, just FYI - https://www.rfc-editor.org/rfc/rfc7946.html#section-3.1.6  
          abhinav Abhi Dangeti added a comment -

          Ah thanks for that Sreekanth Sivasankaran , Aditi Ahuja .

          abhinav Abhi Dangeti added a comment - Ah thanks for that Sreekanth Sivasankaran , Aditi Ahuja .

          Thanks Sreekanth Sivasankaran 

          I'll give it a try but:

          • it means I need a tool to convert my bad geoJSON to a geoJSON in CCW ordering, i.e. respecting really the geoJSON polygons specifications.
          • I will probably not be the only one with such issue so at least a warning in the upcoming documentation on the search on indexed polygons should be added?

          Thanks a lot for your insight!

          fabrice.leray Fabrice Leray added a comment - Thanks Sreekanth Sivasankaran   I'll give it a try but: it means I need a tool to convert my bad geoJSON to a geoJSON in CCW ordering, i.e. respecting really the geoJSON polygons specifications. I will probably not be the only one with such issue so at least a warning in the upcoming documentation on the search on indexed polygons should be added? Thanks a lot for your insight!

          People

            fabrice.leray Fabrice Leray
            fabrice.leray Fabrice Leray
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty