Uploaded image for project: 'Nuxeo Platform'
  1. Nuxeo Platform
  2. NXP-30694

Fix search on float field in Elasticsearch

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Critical
    • Resolution: Not A Bug
    • Affects Version/s: 10.10, 2021.0
    • Fix Version/s: None
    • Component/s: Elasticsearch
    • Backlog priority:
      900
    • Sprint:
      nxplatform #49
    • Story Points:
      3

      Description

      When searching documents in elasticsearch based on a field of type float (type Floating point in Studio, type xs:double in the schema), it returns documents that don't respond to the search.

      How to reproduce:

      • in Studio Modeler, define a new document type name MyDoc with a field of type Floating point named float_field
      • deploy
      • in the Nuxeo instance, create a document of type MyDoc with field float_field set to 1:
        curl -XPOST -H "properties:*" -H 'Content-Type:application/json' \
        http://localhost:8080/nuxeo/api/v1/repo/default/path/default-domain/workspaces/ws1 \
        -d '{ "entity-type":"document", "name":"MyDoc1","type":"MyDoc", "properties": { "dc:title":"MyDoc1", "mydoc:float_field":1} }'
        
      • create a 2nd document of type MyDoc with field float_field set to 2
        curl -XPOST -H "properties:*" -H 'Content-Type:application/json' \
        http://localhost:8080/nuxeo/api/v1/repo/default/path/default-domain/workspaces/ws1 \
        -d '{ "entity-type":"document", "name":"MyDoc2","type":"MyDoc", "properties": { "dc:title":"MyDoc2", "mydoc:float_field":2} }'
        
      • search for the document with property mydoc:float_field set to 1 in elasticsearch (using e.g. the Elasticsearch passthrough):
        curl -u Administrator:Administrator -H 'Content-Type: application/json' 'http://localhost:8080/nuxeo/site/es/nuxeo/_search?pretty' -d '{
          "query": {"bool": {"must": [
            {"term": { "ecm:isVersion": "false"}},
            {"term": { "ecm:isTrashed": "false"}},
            {"term": { "ecm:isProxy": "false"}},
            {"term": { "mydoc:float_field": 1}},
            {"term": { "ecm:primaryType": "MyDoc"}}
          ]}}
        }'
        

      Expect result: the elasticsearch search returns 1 result, MyDoc1 document
      Actual result: the elasticsearch search returns all the documents of type MyDoc

      FYI the mapping in elasticsearch is automatically defined like this:

                "mydoc:float_field" : {
                  "type" : "float"
                },
      

      Executing a page provider configured to use elasticsearch using REST API endpoint api/v1/search/pp/$PP/execute gives the same result. The Nuxeo Platform generates a DSL query looking like this:

      {
        "from": 0,
        "size": 40,
        "query": {
          "bool": {
            "must": [
              {
                "constant_score": {
                  "filter": {
                    "bool": {
                      "must_not": [
                        {
                          "term": {
                            "ecm:mixinType": {
                              "value": "HiddenInNavigation",
                              "boost": 1
                            }
                          }
                        }
                      ],
                      "adjust_pure_negative": true,
                      "boost": 1
                    }
                  },
                  "boost": 1
                }
              },
              {
                "constant_score": {
                  "filter": {
                    "term": {
                      "ecm:isProxy": {
                        "value": "false",
                        "boost": 1
                      }
                    }
                  },
                  "boost": 1
                }
              },
              {
                "constant_score": {
                  "filter": {
                    "term": {
                      "ecm:isVersion": {
                        "value": "false",
                        "boost": 1
                      }
                    }
                  },
                  "boost": 1
                }
              },
              {
                "constant_score": {
                  "filter": {
                    "bool": {
                      "must_not": [
                        {
                          "term": {
                            "ecm:isTrashed": {
                              "value": true,
                              "boost": 1
                            }
                          }
                        }
                      ],
                      "adjust_pure_negative": true,
                      "boost": 1
                    }
                  },
                  "boost": 1
                }
              },
              {
                "constant_score": {
                  "filter": {
                    "term": {
                      "ecm:primaryType": {
                        "value": "MyDoc",
                        "boost": 1
                      }
                    }
                  },
                  "boost": 1
                }
              },
              {
                "constant_score": {
                  "filter": {
                    "term": {
                      "mydoc:float_field": {
                        "value": "1",
                        "boost": 1
                      }
                    }
                  },
                  "boost": 1
                }
              }
            ],
            "adjust_pure_negative": true,
            "boost": 1
          }
        },
        "_source": {
          "includes": [
            "_id"
          ],
          "excludes": []
        }
      }
      

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: