Queries with curl/http requests

    +
    Couchbase Full Text Search supports running multiple types of queries through curl/http request.

    Term Query

    The below sample responds with a list of documents in which the field type contains the term airline.

    The query works only for the terms with single word.

    Curl Request

    curl -XPOST -H "Content-Type: application/json" -u <username>:<password> http://localhost:8094/api/index/DemoIndex/query -d
    '{
    	"query": {
    		"term": "giverny",
    		"field": "title"
    	}
    }'

    Curl Response

    {
      "status":{
        "total":1,
        "failed":0,
        "successful":1
      },
      "request":{
        "query":{
          "term":"giverny",
          "field":"title"
        },
        "size":10,
        "from":0,
        "highlight":null,
        "fields":null,
        "facets":null,
        "explain":false,
        "sort":["-_score"],
        "includeLocations":false,
        "search_after":null,
        "search_before":null
      },
      "hits":[
        {
          "index":"DemoIndex_76059e8b3887351c_4c1c5584",
          "id":"hotel_10064",
          "score":10.033205341869529,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_76059e8b3887351c_4c1c5584",
          "id":"hotel_10063",
          "score":10.033205341869529,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        }
      ],
      "total_hits":2,
      "max_score":10.033205341869529,
      "took":219177695,
      "facets":null
    }

    Phrase query

    The below sample responds with a list of documents in which the field title contains specified phrase. For example, Glossop or Giverny.

    Curl Request

    curl -XPOST -H "Content-Type: application/json" -u <username>:<password> http://localhost:8094/api/index/DemoIndex/query -d
    '{
    	"query": {
    		"terms": ["glencoe", "youth", "hostel"],
    		"field": "name"
    	}
    }'

    Curl Response

    {
      "status":{
        "total":1,
        "failed":0,
        "successful":1
      },
      "request":{
        "query":{
          "terms":["glencoe","youth","hostel"],
          "field":"name"
        },
        "size":10,
        "from":0,
        "highlight":null,
        "fields":null,
        "facets":null,
        "explain":false,
        "sort":["-_score"],
        "includeLocations":false,
        "search_after":null,
        "search_before":null
      },
      "hits":[
        {
          "index":"DemoIndex_76059e8b3887351c_4c1c5584",
          "id":"hotel_10142",
          "score":8.77552218572323,
          "locations":{
            "name":{
              "glencoe":[
                {
                  "pos":1,
                  "start":0,
                  "end":7,
                  "array_positions":null
                }
              ],
              "hostel":[
                {
                  "pos":3,
                  "start":14,
                  "end":20,
                  "array_positions":null
                }
              ],
              "youth":[
                {
                  "pos":2,
                  "start":8,
                  "end":13,
                  "array_positions":null
                }
              ]
            }
          },
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        }
      ],
      "total_hits":1,
      "max_score":8.77552218572323,
      "took":199844879,
      "facets":null
    }

    Match Query

    The below sample responds with a list of documents in which the field name contains the exact matching term specified in the term field. For example, "40-Mile Air".

    Curl Request

    curl -XPOST -H "Content-Type: application/json" -u <username>:<password> http://localhost:8094/api/index/DemoIndex/query -d '{
    "query": {
      "field": "name",
      "match": "40-Mile Air"
      }
    }'

    Curl Response

    {
      "status":{
        "total":1,
        "failed":0,
        "successful":1
      },
    	"request":{
        "query":{
          "match":"40-Mile Air",
          "field":"name",
          "prefix_length":0,
          "fuzziness":0,
          "operator":"or"
        },
        "size":10,
        "from":0,
        "highlight":null,
        "fields":null,
        "facets":null,
        "explain":false,
        "sort":["-_score"],
        "includeLocations":false,
        "search_after":null,
        "search_before":null
      },
    	"hits":[
    		{
          "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
          "id":"airportDoc",
          "score":10.30528795525373,
          "sort":["_score"],
          "fields":{"_$c":"airline"}
        },
        {
          "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
          "id":"hotel_16687",
          "score":1.085367329598051,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        }
      ],
    	"total_hits":2,
      "max_score":10.30528795525373,
      "took":86844745,
      facets":null
    }

    Match_Phrase query

    The below sample responds with a list of documents in which the field name contains the exactly matching phrase specifed in match_phrase. For example, 40-Mile Air.

    Curl Request

    curl -XPOST -H "Content-Type: application/json" -u <username>:<password> http://localhost:8094/api/index/DemoIndex/query -d '{
      "query": {
        "match_phrase": "40-Mile Air",
        "field": "name"
      }
    }'

    Curl Response

    {
      "status":{
        "total":1,
        "failed":0,
        "successful":1
      },
      "request":{
        "query":{
          "match_phrase":
          "40-Mile Air",
          "field":"name"
        },
        "size":10,
        "from":0,
        "highlight":null,
        "fields":null,
        "facets":null,
        "explain":false,
        "sort":["-_score"],
        "includeLocations":false,
        "search_after":null,
        "search_before":null
      },
      "hits":[
        {
          "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
          "id":"airportDoc",
          "score":10.305287955253732,
          "locations":{
            "name":{
              "40":[
                {
                  "pos":1,
                  "start":0,
                  "end":2,
                  "array_positions":null
                }
              ],
              "air":[
                {
                  "pos":3,
                  "start":8,
                  "end":11,
                  "array_positions":null
                }
              ],
              "mile":[
                {
                  "pos":2,
                  "start":3,
                  "end":7,
                  "array_positions":null
                }
              ]
            }
          },
          "sort":["_score"],
          "fields":{"_$c":"airline"}
        }
      ],
      "total_hits":1,
      "max_score":10.305287955253732,
      "took":62498613,
      "facets":null
    }

    Fuzzy Query

    The below sample responds with a list of documents in which the field name contains the term that matches with the phrase specified in the match field. For example, 40-Mile Air. It considers the matching to a degree specified in the fuzziness field instead of exact matching.

    Curl Request

    curl -XPOST -H "Content-Type: application/json" -u <username>:<password> http://localhost:8094/api/index/DemoIndex/query -d '{
      "query": {
        "field": "name",
        "match": "40-Mile Air",
        "fuzziness": 2
      }
    }'

    Curl Response

    {
      "status":{
        "total":1,
        "failed":0,
        "successful":1
      },
      "request":{
        "query":{
          "match":"40-Mile Air",
          "field":"name",
          "prefix_length":0,
          "fuzziness":2,
          "operator":"or"
        },
        "size":10,
        "from":0,
        "highlight":null,
        "fields":null,
        "facets":null,
        "explain":false,
        "sort":["-_score"],
        "includeLocations":false,
        "search_after":null,
        "search_before":null
      },
      "hits":[
          {
            "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
            "id":"hotel_19199","score":0.17049220881184127,
            "sort":["_score"],
            "fields":{"_$c":"hotel"}
          },
          {
            "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
            "id":"airportDoc",
            "score":0.0956994969941305,
            "sort":["_score"],
            "fields":{"_$c":"airline"}
          },
          {
            "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
            "id":"hotel_21608",
            "score":0.05690871682349641,
            "sort":["_score"],
            "fields":{"_$c":"hotel"}
          },
          {
            "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
            "id":"hotel_19326",
            "score":0.05579005002540549,
            "sort":["_score"],
            "fields":{"_$c":"hotel"}
          },
          {
            "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
            "id":"hotel_21037",
            "score":0.05061580360832486,
            "sort":["_score"],
            "fields":{"_$c":"hotel"}
          },
          {
            "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
            "id":"hotel_35854",
            "score":0.04431672583269436,
            "sort":["_score"],
            "fields":{"_$c":"hotel"}
          },
          {
            "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
            "id":"hotel_3491",
            "score":0.04321478718467854,
            "sort":["_score"],
            "fields":{"_$c":"hotel"}
          },
          {
            "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
            "id":"hotel_20421",
            "score":0.04286437075446538,
            "sort":["_score"],
            "fields":{"_$c":"hotel"}
          },
          {
            "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
            "id":"hotel_1362",
            "score":0.037911531284201695,
            "sort":["_score"],
            "fields":{"_$c":"hotel"}
          },
          {
            "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
            "id":"hotel_21721",
            "score":0.037911531284201695,
            "sort":["_score"],
            "fields":{"_$c":"hotel"}
          }
        ],
        "total_hits":163,
        "max_score":0.17049220881184127,
        "took":21410046,
        "facets":null
      }

    Curl Request

    curl -XPOST -H "Content-Type: application/json" -u <username>:<password> http://localhost:8094/api/index/DemoIndex/query -d '{
      "query": {
        "field": "name",
        "match": "40-Mile Air",
        "fuzziness": 1
      },
      "includeLocations": true
    }'

    Curl Response

    {
      "status":{
        "total":1,
        "failed":0,
        "successful":1
      },
    	"request":{
        "query":{
          "match":"40-Mile Air",
          "field":"name",
          "prefix_length":0,
          "fuzziness":0,
          "operator":"or"
        },
        "size":10,
        "from":0,
        "highlight":null,
        "fields":null,
        "facets":null,
        "explain":false,
        "sort":["-_score"],
        "includeLocations":false,
        "search_after":null,
        "search_before":null
      },
    	"hits":[
        {
          "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
          "id":"airportDoc",
          "score":10.30528795525373,
          "sort":["_score"],
          "fields":{"_$c":"airline"}
        },
        {
          "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
          "id":"hotel_16687",
          "score":1.085367329598051,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        }
      ],
    	"total_hits":2,
      "max_score":10.30528795525373,
      "took":86844745,
      "facets":null
    }

    Curl Request

    curl -XPOST -H "Content-Type: application/json" -u <username>:<password> http://localhost:8094/api/index/DemoIndex/query -d '{
      "query": {
        "field": "name",
        "match": "40-Mile Air",
        "fuzziness": 2
      },
      "includeLocations": true, "analyzer": "standard"
    }'

    Curl Response

    {
      "status":{
        "total":1,
        "failed":0,
        "successful":1
      },
      "request":{
        "query":{
          "match":"40-Mile Air",
          "field":"name",
          "prefix_length":0,
          "fuzziness":2,
          "operator":"or"
        },
        "size":10,
        "from":0,
        "highlight":null,
        "fields":null,
        "facets":null,
        "explain":false,
        "sort":["-_score"],
        "includeLocations":true,
        "search_after":null,
        "search_before":null
      },
      "hits":[
        {
          "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
          "id":"hotel_19199",
          "score":0.17049220881184127,
          "locations":{
            "name":{
              "aire":[
                {
                  "pos":1,
                  "start":0,
                  "end":4,
                  "array_positions":null
                },
                {
                  "pos":5,
                  "start":26,
                  "end":30,
                  "array_positions":null
                }
              ],
              "le":[
                {
                  "pos":3,
                  "start":15,
                  "end":17,
                  "array_positions":null
                }
              ]
            }
          },
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
          "id":"airportDoc",
          "score":0.0956994969941305,
          "locations":{
            "name":{
              "40":[
                {
                  "pos":1,
                  "start":0,
                  "end":2,
                  "array_positions":null
                }
              ],
              "air":[
                {
                  "pos":3,
                  "start":8,
                  "end":11,
                  "array_positions":null
                }
              ],
              "mile":[
                {
                  "pos":2,
                  "start":3,
                  "end":7,
                  "array_positions":null
                }
              ]
            }
          },
          "sort":["_score"],
          "fields":{"_$c":"airline"}
        },
        {
          "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
          "id":"hotel_21608",
          "score":0.05690871682349641,
          "locations":{
            "name":{
              "le":[
                {
                  "pos":2,
                  "start":6,
                  "end":8,
                  "array_positions":null
                }
              ],
              "m":[
                {
                  "pos":3,
                  "start":9,
                  "end":10,
                  "array_positions":null
                }
              ]
            }
          },
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
          "id":"hotel_20421",
          "score":0.04286437075446538,
          "locations":{
            "name":{
              "nh":[
                {
                  "pos":1,
                  "start":0,
                  "end":2,
                  "array_positions":null
                }
              ],
              "nice":[
                {
                  "pos":2,
                  "start":3,
                  "end":7,
                  "array_positions":null
                }
              ]
            }
          },
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
          "id":"hotel_1362",
          "score":0.037911531284201695,
          "locations":{
            "name":{
              "au":[
                {
                  "pos":1,
                  "start":0,
                  "end":2,
                  "array_positions":null
                }
              ]
            }
          },
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
          "id":"hotel_21721",
          "score":0.037911531284201695,
          "locations":{
            "name":{
              "iv":[
                {
                  "pos":3,
                  "start":12,
                  "end":14,
                  "array_positions":null
                }
              ]
            }
          },
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        }
      ],
      "total_hits":163,
      "max_score":0.17049220881184127,
      "took":610500365,
      "facets":null
    }

    Prefix Query

    The below sample responds with a list of documents in which the name field contains the text that starts with the given prefix. For example, Air.

    Curl Request

    curl -XPOST -H "Content-Type: application/json" -u <username>:<password> http://localhost:8094/api/index/DemoIndex/query -d '{
      "fields" : ["name"],
      "query": {
        "field": "name",
        "prefix": "glasgow"
      }
    }'

    Curl Response

    {
      "status":{
        "total":1,
        "failed":0,
        "successful":1
      },
      "request":{
        "query":{
          "prefix":"glasgow",
          "field":"name"
        },
        "size":10,
        "from":0,
        "highlight":null,
        "fields":["name"],
        "facets":null,
        "explain":false,
        "sort":["-_score"],
        "includeLocations":false,
        "search_after":null,
        "search_before":null
      },
      "hits":[
        {
          "index":"DemoIndex_76059e8b3887351c_4c1c5584",
          "id":"hotel_10138",
          "score":6.026769086106564,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        }
      ],
      "total_hits":1,
      "max_score":6.026769086106564,
      "took":181596318,
      "facets":null
    }

    Regex Query

    The below sample responds with a list of documents in which the name field contains the text in the given form of a regular expression. For example, airport.

    Curl Request

    curl -XPOST -H "Content-Type: application/json" -u <username>:<password> http://localhost:8094/api/index/DemoIndex/query -d '{
    "query":{
        "field":"name","regexp":"a[h-i]r[o-p]+ort"}
      }'

    Curl Response

    {
      "status":{
        "total":1,
        "failed":0,
        "successful":1
      },
      "request":{
        "query":{
          "regexp":"a[h-i]r[o-p]+ort",
          "field":"name"},
          "size":10,
          "from":0,
          "highlight":null,
          "fields":null,
          "facets":null,
          "explain":false,
          "sort":["-_score"],
          "includeLocations":false,
          "search_after":null,
          "search_before":null
        },
      "hits":[
        {
          "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
          "id":"hotel_15913",
          "score":5.0166026709347635,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
          "id":"hotel_37887",
          "score":4.486985781600578,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        }
      ],
      "total_hits":2,
      "max_score":5.0166026709347635,
      "took":64912635,
      "facets":null
    }

    Wildcard Query

    The below sample responds with a list of documents in which the country field contains the name that starts with f and ends with ce. For example, france.

    Curl Request

    curl -XPOST -H "Content-Type: application/json" -u <username>:<password> http://localhost:8094/api/index/DemoIndex/query -d '{
      "size":10,
      "from":10,
      "ctl":{"timeout":30},
      "query":{
        "wildcard":"f*ce",
        "field":"country"
      }
    }'

    Curl Response

    {
      "status":{
        "total":1,
        "failed":0,
        "successful":1
      },
      "request":{
        "query":{
          "wildcard":"f*ce",
          "field":"country"
        },
        "size":10,
        "from":10,
        "highlight":null,
        "fields":null,
        "facets":null,
        "explain":false,
        "sort":["-_score"],
        "includeLocations":false,
        "search_after":null,
        "search_before":null
      },
      "hits":[
        {
          "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
          "id":"hotel_21850",
          "score":6.175990572936377,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
          "id":"hotel_21872",
          "score":6.175990572936377,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
          "id":"hotel_24536",
          "score":6.175990572936377,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
          "id":"hotel_21837",
          "score":6.175990572936377,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
          "id":"hotel_21725",
          "score":6.175990572936377,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
          "id":"hotel_21846",
          "score":6.175990572936377,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
          "id":"hotel_40662",
          "score":6.175990572936377,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
          "id":"hotel_35857",
          "score":6.175990572936377,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
          "id":"hotel_21855",
          "score":6.175990572936377,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
          "id":"hotel_21669","score":6.175990572936377,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        }
      ],
      "total_hits":141,
      "max_score":6.175990572936377,
      "took":49997068,
      "facets":null
    }

    Query String Query

    The below sample responds with a list of documents in which the name field contains the text that starts with air and the country field contains the name france.

    Curl Request

    The name field prefixed with air and the country field contains france.

    curl -XPOST -H "Content-Type: application/json" -u <username>:<password> http://localhost:8094/api/index/DemoIndex/query -d '{
    "query": {"query": "+name:air* +country:france"}}'

    Curl Response

    {
      "status":{
        "total":1,
        "failed":0,
        "successful":1
      },
      "request":{
        "query":{
          "query":"+name:air* +country:france"
        },
        "size":10,
        "from":0,
        "highlight":null,
        "fields":null,
        "facets":null,
        "explain":false,
        "sort":["-_score"],
        "includeLocations":false,
        "search_after":null,
        "search_before":null
      },
      "hits":[
        {
          "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
          "id":"hotel_19199",
          "score":3.166810600229102,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        }
      ],
      "total_hits":1,
      "max_score":3.166810600229102,
      "took":593704,
      "facets":null
    }

    Curl Request

    The below sample responds with a list of documents in which the name field is prefixed with air, and the country field contains anything other than france.

    curl -XPOST -H "Content-Type: application/json" -u <username>:<password> http://localhost:8094/api/index/DemoIndex/query -d '{
    "query": {"query": "+name:air* -country:france"}}'

    Curl Response

    {
      "status":{
        "total":1,
        "failed":0,
        "successful":1
      },
      "request":{
        "query":{
          "query":"+name:air* -country:france"
        },
        "size":10,
        "from":0,
        "highlight":null,
        "fields":null,
        "facets":null,
        "explain":false,
        "sort":["-_score"],
        "includeLocations":false,
        "search_after":null,
        "search_before":null
      },
      "hits":[
        {
          "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
          "id":"airportDoc",
          "score":1.0997886699799067,
          "sort":["_score"],
          "fields":{"_$c":"airline"}
        },
        {
          "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
          "id":"hotel_16687",
          "score":1.0997886699799067,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
          "id":"hotel_15913",
          "score":0.9524449440916017,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
          "id":"hotel_37887",
          "score":0.8518926457255296,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        }
      ],
      "total_hits":4,
      "max_score":1.0997886699799067,
      "took":537291,
      "facets":null
    }

    Boosting the score

    The below sample responds with a list of documents in which both the type field and name field contains the term airport but the relevancy of the specified term, for example, airport is more in the name field than the type field.

    Curl Request

    curl -XPOST -H "Content-Type: application/json" -u <username>:<password> http://localhost:8094/api/index/DemoIndex/query -d '{
    "query": {
     "disjuncts":[
        {
         "field":"city",
         "match": "glossop",
         "boost":5
        },
        {
          "field":"title",
          "match":"glossop"
        }
      ]
    }'

    Curl Response

    {
      "status":{
        "total":1,
        "failed":0,
        "successful":1
      },
      "request":{
        "query":{
          "disjuncts":[
            {
              "match":"glossop",
              "field":"city",
              "boost":5,
              "prefix_length":0,
              "fuzziness":0,
              "operator":"or"
            },
            {
              "match":"glossop",
              "field":"title",
              "prefix_length":0,
              "fuzziness":0,
              "operator":"or"
            }
          ],
          "min":0
        },
        "size":10,
        "from":0,
        "highlight":null,
        "fields":null,
        "facets":null,
        "explain":false,
        "sort":["-_score"],
        "includeLocations":false,
        "search_after":null,
        "search_before":null
      },
      "hits":[
        {
          "index":"DemoIndex_41b91e3a4134783d_4c1c5584",
          "id":"hotel_10161",
          "score":11.390925020776914,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_41b91e3a4134783d_4c1c5584",
          "id":"hotel_10158",
          "score":11.390925020776914,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_41b91e3a4134783d_4c1c5584",
          "id":"hotel_10160",
          "score":11.390925020776914,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_41b91e3a4134783d_4c1c5584",
          "id":"hotel_10159",
          "score":0.9131614588308529,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        }
      ],
      "total_hits":4,
      "max_score":11.390925020776914,
      "took":339907764,
      "facets":null
    }

    Conjuncts and Disjuncts

    The below sample responds with a list of documents in which the name field contains the text that starts with air and the testing field is not false, and the country field does not contain france.

    Curl Request

    curl -XPOST -H "Content-Type: application/json" -u <username>:<password> http://localhost:8094/api/index/DemoIndex/query -d '{
      "query": {
        "conjuncts": [
          {
            "query": "+name:air*"
          },
          {
            "disjuncts": [
              {"query": "+testing:false"},
              {"query": "country:france"}
            ]
          }
        ]
      }
    }'

    Curl Response

    {
      "status":{
        "total":1,
        "failed":0,
        "successful":1
      },
      "request":{
        "query":{
          "conjuncts":[
            {
              "query":"+name:air*"
            },
            {
              "disjuncts":[
                {
                  "query":"+testing:false"
                },
                {
                  "query":"country:france"
                }
              ],
              "min":0
            }
          ]
        },
        "size":10,
        "from":0,
        "highlight":null,
        "fields":null,
        "facets":null,
        "explain":false,
        "sort":["-_score"],
        "includeLocations":false,
        "search_after":null,
        "search_before":null
      },
      "hits":[
        {
          "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
          "id":"hotel_19199",
          "score":1.8423829850895888,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        }
      ],
      "total_hits":1,
      "max_score":1.8423829850895888,
      "took":81919182,
      "facets":null
    }

    Boolean Query

    Curl Request

    curl -XPOST -H "Content-Type: application/json" -u <username>:<password> http://localhost:8094/api/index/DemoIndex/query -d '{
      "query" : {
        "must": {
          "conjuncts":[{"field":"type", "match": "hotel"}, {"field":"country", "match": "france"}]
        },
        "must_not": {
          "disjuncts": [{"field":"country", "match": "united states"}]
        },
        "should": {
          "disjuncts": [{"field":"free_parking", "bool": true}]
        }
      }
    }'

    Curl Response

    {
      "status":{
        "total":1,
        "failed":0,
        "successful":1
      },
      "request":{
        "query":{
          "must":{
            "conjuncts":[
              {
                "match":"hotel",
                "field":"type",
                "prefix_length":0,
                "fuzziness":0,
                "operator":"or"
              },
              {
                "match":"france",
                "field":"country",
                "prefix_length":0,
                "fuzziness":0,
                "operator":"or"
              }
            ]
          },
          "should":{
            "disjuncts":[
              {
                "bool":true,
                "field":"free_parking"
              }
            ],
            "min":0
          },
          "must_not":{
            "disjuncts":[
              {
                "match":"united states",
                "field":"country",
                "prefix_length":0,
                "fuzziness":0,
                "operator":"or"
              }
            ],
            "min":0
          }
        },
        "size":10,
        "from":0,
        "highlight":null,
        "fields":null,
        "facets":null,
        "explain":false,
        "sort":["-_score"],
        "includeLocations":false,
        "search_after":null,
        "search_before":null
      },
      "hits":[
        {
          "index":"DemoIndex_76059e8b3887351c_4c1c5584",
          "id":"hotel_21720",
          "score":9.381573976364228,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_76059e8b3887351c_4c1c5584",
          "id":"hotel_21849",
          "score":9.381573976364228,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_76059e8b3887351c_4c1c5584",
          "id":"hotel_20419",
          "score":9.381573976364228,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_76059e8b3887351c_4c1c5584",
          "id":"hotel_21725",
          "score":9.381573976364228,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_76059e8b3887351c_4c1c5584",
          "id":"hotel_20422",
          "score":9.381573976364228,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_76059e8b3887351c_4c1c5584",
          "id":"hotel_21852",
          "score":9.381573976364228,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_76059e8b3887351c_4c1c5584",
          "id":"hotel_21657",
          "score":9.381573976364228,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_76059e8b3887351c_4c1c5584",
          "id":"hotel_21838",
          "score":9.381573976364228,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_76059e8b3887351c_4c1c5584",
          "id":"hotel_21723",
          "score":9.381573976364228,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_76059e8b3887351c_4c1c5584",
          "id":"hotel_1359",
          "score":9.381573976364228,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        }
      ],
      "total_hits":140,
      "max_score":9.381573976364228,
      "took":116599230,
      "facets":null
    }

    Date Range Query

    This example needs an index created on beer-sample bucket.

    The below sample responds with a list of documents in which the updateOn field contains the date in between the start date and end date, both inclusive.

    Curl Request

    curl -XPOST -H "Content-Type: application/json" -u <username>:<password> http://localhost:8094/api/index/<beer-sample-index-name>/query -d '{
      "query": {
        "start": "2001-01-01","inclusive_start": true,"end": "2021-08-11","inclusive_end": true,"field": "updated"
      }
    }'

    Curl Response

    {
      "status": {
      "total": 1,
      "failed": 0,
      "successful": 1
      },
      "request": {
      "query": {
          "start": "2001-01-01T00:00:00Z",
          "end": "2021-08-11T00:00:00Z",
          "inclusive_start": true,
          "inclusive_end": true,
          "field": "updated"
      },
      "size": 10,
      "from": 0,
      "highlight": null,
      "fields": null,
      "facets": null,
      "explain": false,
      "sort": ["-_score"],
      "includeLocations": false,
      "search_after": null,
      "search_before": null
      },
      "hits": [
        {
          "index": "bix_3a91439dbf1df8ee_4c1c5584",
          "id": "devil_s_canyon",
          "score": 0.716641821033877,
          "sort": ["_score"]
        },
        {
          "index": "bix_3a91439dbf1df8ee_4c1c5584",
          "id": "abita_brewing_company-strawberry",
          "score": 0.716641821033877,
          "sort": ["_score"]
        },
        ...
        {
          "index": "bix_3a91439dbf1df8ee_4c1c5584",
          "id": "cains-2008_culture_beer",
          "score": 0.716641821033877,
          "sort": ["_score"]
        },
        {
          "index": "bix_3a91439dbf1df8ee_4c1c5584",
          "id": "element_brewing_company-dark_element",
          "score": 0.716641821033877,
          "sort": ["_score"]
        }
      ],
      "total_hits": 7303,
      "max_score": 0.716641821033877,
      "took": 1447295,
      "facets": null
    }

    Numeric Range Query

    The below sample responds with a list of documents in which the id field is between the specified maximum (max) and minimum (min) values.

    Curl Request

    curl -XPOST -H "Content-Type: application/json" -u <username>:<password> http://localhost:8094/api/index/DemoIndex/query -d '{
      "query":{
        "field":"id",
        "max": 8100,
        "min": 8080
      }
    }'

    Curl Response

    {
      "status":{
        "total":1,
        "failed":0,
        "successful":1
      },
      "request":{
        "query":{
          "min":10025,
          "max":10030,
          "field":"id"
        },
        "size":10,
        "from":0,
        "highlight":null,
        "fields":null,
        "facets":null,
        "explain":false,
        "sort":["-_score"],
        "includeLocations":false,
        "search_after":null,
        "search_before":null
      },
      "hits":[
        {
          "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
          "id":"hotel_10025",
          "score":0.922656832718857,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
          "id":"hotel_10026",
          "score":0.922656832718857,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        }
      ],
      "total_hits":2,
      "max_score":0.922656832718857,
      "took":62274941,
      "facets":null
    }

    DOC_ID QUERY

    The below sample responds with a list of documents in which the document ID is any of the specified ids. For example, airline_10 and airline_10123.

    Curl Request

    curl -XPOST -H "Content-Type: application/json" -u <username>:<password> http://localhost:8094/api/index/DemoIndex/query -d '{
      "query":{
        "ids":["airline_10", "airline_10123"]
      }
    }'

    Curl Response

    {
      "status":{
        "total":1,
        "failed":0,
        "successful":1
      },
      "request":{
        "query":{
          "ids":["airline_10","airline_10123"]
        },
        "size":10,
        "from":0,
        "highlight":null,
        "fields":null,
        "facets":null,
        "explain":false,
        "sort":["-_score"],
        "includeLocations":false,
        "search_after":null,
        "search_before":null
      },
      "hits":[
        {
          "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
          "id":"airline_10",
          "score":1,
          "sort":["_score"],
          "fields":{"_$c":"airline"}
        },
        {
          "index":"DemoIndex_580e3ee6ba3ac900_4c1c5584",
          "id":"airline_10123",
          "score":1,
          "sort":["_score"],
          "fields":{"_$c":"airline"}
        }
      ],
      "total_hits":2,
      "max_score":1,
      "took":139708973,
      "facets":null
    }

    Bounded Rectangle Query

    The below sample responds with a list of documents in which the geolocation (geo) is bounded between the specified top_left and bottom_right.

    Curl Request

    curl -XPOST -H "Content-Type: application/json" -u <username>:<password> http://localhost:8094/api/index/DemoIndex/query -d '{
      "query": {
        "field": "geo",
        "bottom_right": [-66.9326, 24.9493],
        "top_left": [-125.0011, 49.5904]
      }
    }'

    Curl Response

    {
      "status":{
        "total":1,
        "failed":0,
        "successful":1
      },
      "request":{
        "query":{
          "top_left":[-125.0011,49.5904],
          "bottom_right":[-66.9326,24.9493],
          "field":"geo"
        },
        "size":10,
        "from":0,
        "highlight":null,
        "fields":null,
        "facets":null,
        "explain":false,
        "sort":["-_score"],
        "includeLocations":false,
        "search_after":null,
        "search_before":null
      },
      "hits":[
        {
          "index":"DemoIndex_76059e8b3887351c_4c1c5584",
          "id":"hotel_23634",
          "score":0.5583933812203372,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_76059e8b3887351c_4c1c5584",
          "id":"hotel_17932",
          "score":0.5583933812203372,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_76059e8b3887351c_4c1c5584",
          "id":"hotel_25325",
          "score":0.2575082889947619,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_76059e8b3887351c_4c1c5584",
          "id":"hotel_25155",
          "score":0.2575082889947619,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_76059e8b3887351c_4c1c5584",
          "id":"hotel_25263",
          "score":0.2575082889947619,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_76059e8b3887351c_4c1c5584",
          "id":"hotel_3785",
          "score":0.2575082889947619,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_76059e8b3887351c_4c1c5584",
          "id":"hotel_25302",
          "score":0.2575082889947619,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_76059e8b3887351c_4c1c5584",
          "id":"hotel_25195",
          "score":0.2575082889947619,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_76059e8b3887351c_4c1c5584",
          "id":"hotel_25161",
          "score":0.2575082889947619,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_76059e8b3887351c_4c1c5584",
          "id":"hotel_25119",
          "score":0.2575082889947619,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        }
      ],
      "total_hits":361,
      "max_score":0.5583933812203372,
      "took":473390831,
      "facets":null
    }

    Point Distance Query

    The below sample responds with a list of documents in which the location specified as geolocation is in the proximity of the distance specified in distance field. A location is represented by means of longitude-latitude coordinate pairs.

    Curl Request

    curl -XPOST -H "Content-Type: application/json" -u <username>:<password> http://localhost:8094/api/index/DemoIndex/query -d '{
          "from": 0,
          "size": 10,
          "query": {
            "location": {
              "lon": -2.235143,
              "lat": 53.482358
            },
            "distance": "1mi",
            "field": "geo"
          },
          "sort": [
            {
              "by": "geo_distance",
              "field": "geo",
              "unit": "mi",
              "location": {
                "lon": -2.235143,
                "lat": 53.482358
              }
            }
          ]
        }'

    Curl Response

    {
      "status":{
        "total":1,
        "failed":0,
        "successful":1
      },
      "request":{
        "query":{
          "location":[-2.235143,53.482358],
          "distance":"1mi",
          "field":"geo"
        },
        "size":10,
        "from":0,
        "highlight":null,
        "fields":null,
        "facets":null,
        "explain":false,
        "sort":[
          {
            "by":"geo_distance",
            "field":"geo",
            "location":{
              "lat":53.482358,
              "lon":-2.235143
            },
            "unit":"mi"
          }
        ],
        "includeLocations":false,
        "search_after":null,
        "search_before":null
      },
      "hits":[
        {
          "index":"DemoIndex_41b91e3a4134783d_4c1c5584",
          "id":"hotel_17413",
          "score":1.2317379157866246,
          "sort":[" \u0001?U]S\\.e\u0002_"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_41b91e3a4134783d_4c1c5584",
          "id":"hotel_17414",
          "score":1.2317379157866246,
          "sort":[" \u0001?Z\u0000./\u0007Q\u0012\t"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_41b91e3a4134783d_4c1c5584",
          "id":"hotel_17415",
          "score":1.2317379157866246,
          "sort":[" \u0001?lg6,\u003c\u000cIL"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_41b91e3a4134783d_4c1c5584",
          "id":"hotel_17416",
          "score":1.2317379157866246,
          "sort":[" \u0001?r\u003cw\u0005GZ\u0005\u001f"],
          "fields":{"_$c":"hotel"}
        }
      ],
      "total_hits":4,
      "max_score":1.2317379157866246,
      "took":126456906,
      "facets":null
    }

    Date Range Facets Query

    This example needs an index created on beer-sample bucket.

    Curl Request

    curl -XPOST -H "Content-Type: application/json" -u <username>:<password> http://localhost:8094/api/index/<beer-sample-index-name>/query -d '{
      "query": {
        "field": "style",
        "term": "beer"
      },
      "facets": {
        "types": {
          "size": 10,
          "field": "updated",
          "date_ranges": [
            {
              "name": "old",
              "end": "2011-01-01"
            },
            {
              "name": "new",
              "start": "2011-01-02"
            }
          ]
        }
      }
    }'

    Curl Response

    {
      "status": {
        "total": 1,
        "failed": 0,
        "successful": 1
      },
      "request": {
        "query": {
          "term": "beer",
          "field": "style"
        },
        "size": 10,
        "from": 0,
        "highlight": null,
        "fields": null,
        "facets": {
          "types": {
            "size": 10,
            "field": "updated",
            "date_ranges": [
              {
                "end": "2011-01-01",
                "name": "old",
                "start": "0001-01-01T00:00:00Z"
              },
              {
                "end": "0001-01-01T00:00:00Z",
                "name": "new",
                "start": "2011-01-02"
              }
            ]
          }
        },
        "explain": false,
        "sort": [
          "-_score"
        ],
        "includeLocations": false,
        "search_after": null,
        "search_before": null
      },
      "hits": [
        {
          "index": "bix_3a91439dbf1df8ee_4c1c5584",
          "id": "erie_brewing_company-derailed_black_cherry_ale",
          "score": 3.8396833650222075,
          "sort": ["_score"]
        },
        {
          "index": "bix_3a91439dbf1df8ee_4c1c5584",
          "id": "smuttynose_brewing_co-smuttynose_pumpkin_ale",
          "score": 3.8396833650222075,
          "sort": ["_score"]
        },
        ...
        {
          "index": "bix_3a91439dbf1df8ee_4c1c5584",
          "id": "warwick_valley_wine_co-doc_s_hard_apple_cider",
          "score": 3.8396833650222075,
          "sort": ["_score"]
        }
      ],
      "total_hits": 86,
      "max_score": 3.8396833650222075,
      "took": 155002,
      "facets": {
        "types": {
          "field": "updated",
          "total": 86,
          "missing": 0,
          "other": 0,
          "date_ranges": [
            {
              "name": "old",
              "end": "2011-01-01T00:00:00Z",
              "count": 81
            },
            {
              "name": "new",
              "start": "2011-01-02T00:00:00Z",
              "count": 5
            }
          ]
        }
      }
    }

    Numeric Range facet

    The below sample is to fetch the top 10 hotels based on the ratings given by the customers.

    • Type Mapping ⇒ type:hotel

    • child-field: reviews.ratings.Service

    • Analyzer: standard

    Curl Request

    curl -XPOST -H "Content-Type: application/json" -u <username>:<password> http://localhost:8094/api/index/DemoIndex/query -d '{
      "query": {
        "field": "reviews.content",
        "term": "good"
      },
      "facets": {
        "types": {
          "size": 10,
          "field": "reviews.ratings.Service",
          "numeric_ranges": [
            {
              "name": "Awesome",
              "min": 5
            },
            {
              "name": "Good",
              "max": 4
            },
              {
              "name": "Avg",
              "max": 3
            },
            {
              "name": "Poor",
              "max": 2
            },
            {
              "name": "Bad",
              "max": 1
            }
          ]
        }
      }
    }'

    Curl Response

    {
      "status":{
        "total":1,
        "failed":0,
        "successful":1
      },
      "request":{
        "query":{
          "term":"good",
          "field":"reviews.content"
        },
        "size":10,
        "from":0,
        "highlight":null,
        "fields":null,
        "facets":{
          "types":{
            "size":10,
            "field":"reviews.ratings.Service",
            "numeric_ranges":[
              {
                "name":"Awesome",
                "min":5
              },
              {
                "name":"Good",
                "max":4
              },
              {
                "name":"Avg",
                "max":3
              },
              {
                "name":"Poor",
                "max":2
              },
              {"name":"Bad",
              "max":1
              }
            ]
          }
        },
        "explain":false,
        "sort":["-_score"],
        "includeLocations":false,
        "search_after":null,
        "search_before":null
      },
      "hits":[
        {
          "index":"DemoIndex_41b91e3a4134783d_4c1c5584",
          "id":"hotel_15134",
          "score":1.608775098615459,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_41b91e3a4134783d_4c1c5584",
          "id":"hotel_3491",
          "score":1.5929246603757872,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_41b91e3a4134783d_4c1c5584",
          "id":"hotel_9062",
          "score":1.3135594084905977,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_41b91e3a4134783d_4c1c5584",
          "id":"hotel_25261",
          "score":1.199110122199631,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_41b91e3a4134783d_4c1c5584",
          "id":"hotel_15976",
          "score":1.0384598347067433,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_41b91e3a4134783d_4c1c5584",
          "id":"hotel_26142",
          "score":1.029912757807367,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_41b91e3a4134783d_4c1c5584",
          "id":"hotel_3629",
          "score":0.9683687809619517,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_41b91e3a4134783d_4c1c5584",
          "id":"hotel_5848",
          "score":0.9479798384018671,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_41b91e3a4134783d_4c1c5584",
          "id":"hotel_16443",
          "score":0.9479797868886458,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        },
        {
          "index":"DemoIndex_41b91e3a4134783d_4c1c5584",
          "id":"hotel_2814",
          "score":0.9288267057398083,
          "sort":["_score"],
          "fields":{"_$c":"hotel"}
        }
      ],
      "total_hits":656,
      "max_score":1.608775098615459,
      "took":343585473,
      "facets":{
        "types": {
          "field":"reviews.ratings.Service",
          "total":1871,
          "missing":3,
          "other":0,
          "numeric_ranges":[
            {
              "name":"Good",
              "max":4,"count":658
            },
            {
              "name":"Awesome",
              "min":5,
              "count":579
            },
            {
              "name":"Avg",
              "max":3,
              "count":366
            },
            {
              "name":"Poor",
              "max":2,
              "count":219
            },
            {
              "name":"Bad",
              "max":1,
              "count":49
            }
          ]
        }
      }
    }