Get count based on geo_distance filter and term search inside an item attribute in ES 7.10

I'm running Elasticsearch version: 7.10 with an index and below you have an example for an index item:

{
	"_index": "wonder-search",
	"_type": "_doc",
	"_id": "Bvpam4UBCGd9T_03g7QP",
	"_version": 1,
	"_seq_no": 2000,
	"_primary_term": 1,
	"found": true,
	"_source": {
		"sort": "4001",
		"item_id": "4970",
		"user_id": "468",
		"user_icon": "/site-content/avatars/gSgAiiNkZ2gQbt8kSWBZalP4eZE3-1597862920426.jpeg",
		"username": "sophiesdelights",
		"item_label": "Baekjeong",
		"search_text_username_json": [
			"sophiesdelights"
		],
		"search_text_caption_json": [
			"My FAVORITE KBBQ Spot! Great quality beef! Love the vibe and unlimited cheese corn and steamed egg sides!"
		],
		"search_text_city_json": [
			"Buena Park"
		],
		"search_text_state_json": [
			"California"
		],
		"search_text_country_json": [
			"United States"
		],
		"search_text_location_name_json": [
			"Baekjeong"
		],
		"search_text_tag_name_json": [
			"korean",
			"restaurant",
			"asian",
			"dining"
		],
		"search_text_cuisine_name_json": [],
		"type": "video",
		"vanity_url": "",
		"icon": "",
		"city": "Buena Park",
		"city_id": "6",
		"latitude": "33.88569750",
		"longitude": "-117.99657830",
		"address": "5171 Beach Blvd",
		"duration": "",
		"video_count": "0",
		"sort_score": "9",
		"filename": "a0430447-0638-4088-8dba-f2b514b8e65d.MOV",
		"is_sandbox": "0",
		"geo_point": {
			"lat": "33.88569750",
			"lon": "-117.99657830"
		},
		"search_text_completion": {
			"input": [
				"Baekjeong"
			],
			"contexts": {
				"type": [
					"video"
				]
			}
		}
	}
}

Now, this is an item type = video and has a latitude and a longitude. This video has a field called search_text_tag_name_json which has some tags inside that json.

Every tag inside that json is also an item in the index.

I'm trying to figure out a way to search for a tag: Ex: korean and also add a geo_distance query and among other things, return the number of videos that are inside that geo_distance filter and have the tag korean in the search_text_tag_name_json field.

I figured everything out but I'm not sure how to add the count based on what I said.

The query right now looks like this:

{
  "_source": [
    "sort",
    "sort_score",
    "item_id",
    "user_id",
    "username",
    "user_icon",
    "item_label",
    "type",
    "vanity_url",
    "latitude",
    "longitude",
    "type",
    "icon",
    "city",
    "city_id",
    "video_count",
    "address",
    "search_text",
    "filename",
    "duration",
    "is_sandbox"
  ],
  "collapse": {
    "field": "item_label"
  },
  "sort": {
    "_score": {
      "order": "desc"
    },
    "video_count": {
      "order": "desc"
    }
  },
  "from": 0,
  "size": 10,
  "query": {
    "bool": {
      "must": [
        {
          "query_string": {
            "query": "*alaska*",
            "fields": [
              "search_text_tag_name_json"
            ]
          }
        },
        {
          "match": {
            "type": "goal"
          }
        }
      ],
      "should": [
        {
          "match": {
            "search_text_tag_name_json": "alaska"
          }
        }
      ],
      "filter": [
        {
          "geo_distance": {
            "distance": "40.2335km",
            "geo_point": {
              "lat": 40.7127753,
              "lon": -74.0059728
            }
          }
        }
      ]
    }
  }
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.