-1

I want to fetch data from elastic search based on status. If the status is active/inactive I want to fetch a list of data.

Here I attached a single record for example. How can I get it?

{
  "took": 2,
  "timed_out": false,
  "_shards": {
    "total": 2,
    "successful": 2,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 1,
      "relation": "eq"
    },
    "max_score": 1.0,
    "hits": [
      {
        "_index": "customer-fr",
        "_type": "_doc",
        "_id": "NFR0002220803",
        "_score": 1.0,
        "_source": {
          "customerManagedBy": "V",
          "numOfBeds": null,
          "legalEntity": null,
          "dependency": null,
          "credentials": [
            
          ],
          "affiliations": [
            {
              "endDate": "2010-06-08",
              "startDate": "2009-08-04",
              "parent": "NFR0002220803",
              "role": "Vice-Président",
              "relationShipType": "Travaille sur",
              "relationshipKey": "NFR0002220803|NFR0002217822|271568|2009-08-04",
              "isPrimary": false,
              "status": "In-Active",
              "child": "NFR0002217822",
              "isDuplicate": false
            },
            {
              "endDate": "2010-06-08",
              "startDate": "2009-08-04",
              "parent": "NFR0002220803",
              "role": "Vice-Président",
              "relationShipType": "Travaille sur",
              "relationshipKey": "NFR0002220803|NFR0002217823|271568|2009-08-04",
              "isPrimary": false,
              "status": "In-Active",
              "child": "NFR0002217823",
              "isDuplicate": false
            },
            {
              "endDate": "2010-06-08",
              "startDate": "2009-08-04",
              "parent": "NFR0002220803",
              "role": "Vice-Président",
              "relationShipType": "Travaille sur",
              "relationshipKey": "NFR0002220803|NFR0002217824|271568|2009-08-04",
              "isPrimary": false,
              "status": "In-Active",
              "child": "NFR0002217824",
              "isDuplicate": false
            },
            {
              "endDate": "2010-06-08",
              "startDate": "2009-08-04",
              "parent": "NFR0002220803",
              "role": "Vice-Président",
              "relationShipType": "Travaille sur",
              "relationshipKey": "NFR0002220803|NFR0002217825|271568|2009-08-04",
              "isPrimary": false,
              "status": "In-Active",
              "child": "NFR0002217825",
              "isDuplicate": false
            },
            {
              "endDate": "2010-06-08",
              "startDate": "2009-08-04",
              "parent": "NFR0002220803",
              "role": "Vice-Président",
              "relationShipType": "Travaille sur",
              "relationshipKey": "NFR0002220803|NFR0002217826|271568|2009-08-04",
              "isPrimary": false,
              "status": "In-Active",
              "child": "NFR0002217826",
              "isDuplicate": false
            }
          ],
          "@timestamp": "2021-11-11T06:49:57.704Z",
          "department": "Instances, Commissions",
          "dispensingFlag": null,
          "hcoType": "divers",
          "specialties": [
            {
              "speciality": "Conseil régional",
              "type": "Primary Specialty",
              "status": "Active"
            }
          ],
          "hcoSubType": "Institutions administratives et politiques",
          "technicalData": {
            "createdOn": "2021-10-19T17:15:46",
            "createdBy": "Techadmin Techadmin (techadmin)",
            "lastUpdateOn": "2021-11-08T15:04:01",
            "updatedBy": "Techadmin Techadmin (techadmin)"
          },
          "organizationName": "COMMISSION PERMANENTE",
          "customerAddresses": [
            {
              "region": "France Métropole",
              "stateOrProvince": "MOSELLE",
              "microBrick": null,
              "startDate": "2009-08-04",
              "addressLine3": null,
              "height": null,
              "addressKey": "NFR0002220803|AFR0000453829|200148|2009-08-04",
              "latitude": null,
              "brick": "57MET",
              "isPrimary": true,
              "addressId": "AFR0000453829",
              "countryName": "France",
              "endDate": "3999-12-31",
              "addressLine2": null,
              "longitude": null,
              "masterAddress": null,
              "addressLine1": "1 PLACE GABRIEL HOCQUARD",
              "postalCode": "57000",
              "addressType": "Primary address",
              "geoCoordinates": null,
              "status": "Active",
              "suburb": null,
              "city": "METZ"
            }
          ],
          "marketAccessFlag": null,
          "noOfPhysicians": null,
          "privacyLawStatus": false,
          "statusDetail": "Closed",
          "customerRecordType": "Health Care Organization",
          "identities": [
            {
              "effectiveDate": "2021-11-08T15:02:50",
              "value": "WFRH00000001",
              "type": "OneKey",
              "expirationDate": null
            }
          ],
          "topCustomerName": null,
          "@version": "1",
          "name": "COMMISSION PERMANENTE",
          "customerType": "Organization",
          "alias": null,
          "country": "France",
          "meansOfContact": [
            
          ],
          "status": "Inactive",
          "customerId": "NFR0002220803"
        }
      }
    ]
  }
}

This is the query I tried to search

GET /customer-fr/_search

{
  "query": {
    "bool": {
      "must": {
        "match_all": {
          
        }
      },
      "filter": {
        "bool": {
          "must": [
            {
              "status": "Inactive"
            }
          ]
        }
      }
    }
  }
halfer
  • 19,824
  • 17
  • 99
  • 186
  • Please always format your JSON before posting - don't paste it as-is and then ask people to format it for you! – halfer Nov 24 '21 at 00:00

1 Answers1

1

You don't need a range query for this. A simple term query like this one should work:

{
  "query": {
    "bool": {
      "filter": {
        "term": {
          "status": "In-Active"
        }
      }
    }
  }
}
Val
  • 207,596
  • 13
  • 358
  • 360