-2

I'm new to graphql and opensearch queries. Here I'm trying to add a filter to existing query for city, my params inside the query are having data with - and spaces. While I'm trying to query it, data is getting filtered only with first word. For example, my params is having an array "cityNames" : ["chicago","new york", "santa-fe"]. Data gets filtered if I use "chicago", but for "new york" I get results only when I give "new" instead of "new york", and for "santa-fe" it doesnt return any data. How to get records from loaddata only for the cityNames matching params?

here are properties: [ "testCode" : { "type": "keyword" }, "cityName" : { "type": "text", "fielddata":true }, ]

    {
  "query": {
    "bool": {
      "must": [
        {
          "script": {
            "script": {
              "params": {
                 "testCodes": [
                  "T","R"
                ],
                "cityNames": [
                  "albuquerque-santa fe",
                  "chicago",
                  "new york"
                ]
              },
              "source": """ if(doc.containsKey('testCode') && !doc['testCode'].empty){      
                                if(params.testCodes.contains(doc['testCode'].value)){
                                    if(params.cityNames.contains(doc['cityName'].value)){
                                            return true;
                                            }
                                        }
                                    } """
            }
          }
        }
      ]
    }
  },
  "size": 10000
}

Data:

{
    "loadData": [
        {
            "testCode": "T",
            "id": "839294",
            "cityName": "ALBUQUERQUE-SANTA FE"
        },
        {
            "testCode": "T",
            "id": "839294",
            "cityName": "ALBUQUERQUE-SANTA FE"
        },
        {
            "testCode": "R",
            "id": "839294",
            "cityName": "ALBUQUERQUE-SANTA FE"
        },
        {
            "testCode": "T",
            "id": "839294",
            "cityName": "CHICAGO"
        },
        {
            "testCode": "R",
            "id": "839294",
            "cityName": "CHICAGO"
        }
        {
            "testCode": "R",
            "id": "839294",
            "cityName": "NEW YORK"
        },
        {
            "testCode": "R",
            "id": "839294",
            "cityName": "ATLANTA"
        },
        {
            "testCode": "T",
            "id": "839294",
            "cityName": "ATLANTA"
        }
    ]
}
raj
  • 11
  • 4

0 Answers0