searching using elastic search gives me following error on console
{"_shards":{"total":5,"successful":0,"failed":5,"failures":[{"index":"test","shard":4,"reason":"BroadcastShardOperationFailedException[[test][4] ]; nested: ElasticSearchException[failed to execute suggest]; nested: ElasticSearchIllegalArgumentException[[suggest] does not support [size]]; "},{"index":"test","shard":3,"reason":"BroadcastShardOperationFailedException[[test][3] ]; nested: ElasticSearchException[failed to execute suggest]; nested: ElasticSearchIllegalArgumentException[[suggest] does not support [size]]; "},{"index":"test","shard":2,"reason":"BroadcastShardOperationFailedException[[test][2] ]; nested: ElasticSearchException[failed to execute suggest]; nested: ElasticSearchIllegalArgumentException[[suggest] does not support [size]]; "},{"index":"test","shard":0,"reason":"BroadcastShardOperationFailedException[[test][0] ]; nested: ElasticSearchException[failed to execute suggest]; nested: ElasticSearchIllegalArgumentException[[suggest] does not support [size]]; "},{"index":"test","shard":1,"reason":"BroadcastShardOperationFailedException[[test][1] ]; nested: ElasticSearchException[failed to execute suggest]; nested: ElasticSearchIllegalArgumentException[[suggest] does not support [size]]; "}]}}
not able to understand probable reason for this i am using tire/karmi for this
the ES version is 0.9.9
this is my mapping code
{
"test" : {
"document" : {
"properties" : {
"artikelnummer" : {
"type" : "string",
"index" : "not_analyzed",
"omit_norms" : true,
"index_options" : "docs"
},
"bestelltext" : {
"type" : "multi_field",
"fields" : {
"bestelltext" : {
"type" : "string"
},
"ngram" : {
"type" : "string",
"index_analyzer" : "ngram_index_analyzer",
"search_analyzer" : "ngram_search_analyzer",
"include_in_all" : false
}
}
},
"bezeichnung" : {
"type" : "multi_field",
"fields" : {
"bezeichnung" : {
"type" : "string"
},
"ngram" : {
"type" : "string",
"index_analyzer" : "ngram_index_analyzer",
"search_analyzer" : "ngram_search_analyzer",
"include_in_all" : false
},
"suggest" : {
"type" : "string",
"analyzer" : "suggest_analyzer",
"include_in_all" : false
}
}
},
"bezeichnung_zusatz" : {
"type" : "multi_field",
"fields" : {
"bezeichnung_zusatz" : {
"type" : "string"
},
"ngram" : {
"type" : "string",
"index_analyzer" : "ngram_index_analyzer",
"search_analyzer" : "ngram_search_analyzer",
"include_in_all" : false
}
}
},
"dimension" : {
"type" : "string",
"include_in_all" : false
},
"eannummer" : {
"type" : "string",
"index" : "not_analyzed",
"omit_norms" : true,
"index_options" : "docs"
},
"gewicht" : {
"type" : "float",
"include_in_all" : false
},
"gruppe" : {
"type" : "multi_field",
"fields" : {
"gruppe" : {
"type" : "string"
},
"ngram" : {
"type" : "string",
"index_analyzer" : "ngram_index_analyzer",
"search_analyzer" : "ngram_search_analyzer",
"include_in_all" : false
}
}
},
"gruppe_nummer" : {
"type" : "string",
"index" : "not_analyzed",
"omit_norms" : true,
"index_options" : "docs",
"include_in_all" : false
},
"gruppe_zusatz" : {
"type" : "multi_field",
"fields" : {
"gruppe_zusatz" : {
"type" : "string"
},
"ngram" : {
"type" : "string",
"index_analyzer" : "ngram_index_analyzer",
"search_analyzer" : "ngram_search_analyzer",
"include_in_all" : false
}
}
},
"hersteller" : {
"type" : "multi_field",
"fields" : {
"hersteller" : {
"type" : "string"
},
"ngram" : {
"type" : "string",
"index_analyzer" : "ngram_index_analyzer",
"search_analyzer" : "ngram_search_analyzer",
"include_in_all" : false
},
"unchanged" : {
"type" : "string",
"index" : "not_analyzed",
"omit_norms" : true,
"index_options" : "docs",
"include_in_all" : false
}
}
},
"hersteller_artikelnummer" : {
"type" : "string",
"index" : "not_analyzed",
"omit_norms" : true,
"index_options" : "docs"
},
"hersteller_nummer" : {
"type" : "string",
"index" : "not_analyzed",
"omit_norms" : true,
"index_options" : "docs",
"include_in_all" : false
},
"hierarchie" : {
"type" : "multi_field",
"fields" : {
"hierarchie" : {
"type" : "string",
"index_analyzer" : "hierarchie_index_analyzer",
"search_analyzer" : "keyword",
"include_in_all" : false
},
"ngram" : {
"type" : "string",
"index_analyzer" : "ngram_index_analyzer",
"search_analyzer" : "ngram_search_analyzer",
"include_in_all" : false
}
}
},
"infotext" : {
"type" : "multi_field",
"fields" : {
"infotext" : {
"type" : "string"
},
"ngram" : {
"type" : "string",
"index_analyzer" : "ngram_index_analyzer",
"search_analyzer" : "ngram_search_analyzer",
"include_in_all" : false
}
}
},
"langtext" : {
"type" : "multi_field",
"fields" : {
"langtext" : {
"type" : "string"
},
"ngram" : {
"type" : "string",
"index_analyzer" : "ngram_index_analyzer",
"search_analyzer" : "ngram_search_analyzer",
"include_in_all" : false
}
}
},
"listenpreis_brutto" : {
"type" : "float",
"include_in_all" : false
},
"listenpreis_netto" : {
"type" : "float",
"include_in_all" : false
},
"matchcode" : {
"type" : "string",
"index" : "not_analyzed",
"omit_norms" : true,
"index_options" : "docs"
},
"mengeneinheit" : {
"type" : "string",
"include_in_all" : false
}
}
}
}
}
This has got nothing to do with your mapping. It's to do with the search call you're making. Somewhere you'll have the "size" keywords within your call to the search API.
It looks like you're using the suggester endpoint and you've got the "size" keyword directly under the "suggest" keyword. Here's an example of my PHP code (I know it's not in Ruby but it still illustrates the point).
$searchParams['body']['suggest'] = array(
'text' => strtolower(trim(urldecode($query))),
'simple_phrase' => array(
'phrase' => array(
'field' => "name",
'size' => 4,
'real_word_error_likelihood' => 0.95,
'confidence' => 1.0,
'gram_size' => 1,
'direct_generator' => array(
array(
"field" => "name",
"suggest_mode" => "always",
"min_word_len" => 1
),
array(
"field" => "name_reverse",
"suggest_mode" => "always",
"min_word_len" => 1,
"pre_filter" => "reverse",
"post_filter" => "reverse"
)
)
)
)
);
You see how I have the "size" keyword under the phrase suggester, rather than under suggester directly.
Related
I am facing issues with elasticsearch aggregation grouping inside top_hits. or i need unique students count in the tophits
Elastic search mapping:
{
"board" : {
"properties" : {
"notApplied" : {
"type" : "date"
}
}
}
}
Query :
{
"size": 0,
"query": {},
"aggs": {
"notApplied": {
"filter": {
"exists": {
"field": "board.notApplied"
}
},
"aggs": {
"top_student_hits": {
"top_hits": {
"sort": [
{
"board.notApplied": {
"order": "desc"
}
}
],
"script_fields": {
"dues": {
"script": {
"source": "if (doc.containsKey('board.notApplied') && doc['board.notApplied'].size() != 0) { (doc['board.notApplied'].value.toInstant().toEpochMilli()-params.date)/86400000 } else { 0; }",
"params": {
"date": 1669939199059 // --> < 1 day
}
}
}
},
"_source": {
"includes": [
"id",
"studentName",
"usercode",
"board.notApplied",
"userId"
]
},
"size": 5
}
}
}
}
}
}
Output for the above query :
{
"took" : 11,
...
"aggregations" : {
"notApplied" : {
"doc_count" : 42,
"top_student_hits" : {
"hits" : {
"total" : {
"value" : 42,
"relation" : "eq"
},
"max_score" : null,
"hits" : [
{
"_index" : "applications",
"_type" : "_doc",
"_id" : "4b85533822f91e9b99392f16dedaae1f",
"_score" : null,
"_source" : {
"board" : {
"notApplied" : "2022-10-25T00:00:00.000Z"
},
"studentName" : "Joe",
"id" : "4b85533822f91e9b99392f16dedaae1f",
"userId" : "45a47d1314041ab287a277679ff19922"
},
"fields" : {
"dues" : [
-37
]
},
"sort" : [
1666656000000
]
},
{
"_index" : "applications",
"_type" : "_doc",
"_id" : "1897f32d2d7f691e42c3fe6ebe631c7d",
"_score" : null,
"_source" : {
"board" : {
"notApplied" : "2022-10-25T00:00:00.000Z"
},
"studentName" : "Joe",
"id" : "1897f32d2d7f691e42c3fe6ebe631c7d",
"userId" : "45a47d1314041ab287a277679ff19922"
},
"fields" : {
"dues" : [
-37
]
},
"sort" : [
1666656000000
]
},
{
"_index" : "applications",
"_type" : "_doc",
"_id" : "f0b25dc9a911782ace5af36db7bfbc1f",
"_score" : null,
"_source" : {
"board" : {
"notApplied" : "2022-10-25T00:00:00.000Z"
},
"studentName" : "Sam",
"id" : "f0b25dc9a911782ace5af36db7bfbc1f",
"userId" : "d84f9e5231daa902c37921de9126cad7"
},
"fields" : {
"dues" : [
-37
]
},
"sort" : [
1666656000000
]
},
{
"_index" : "applications",
"_type" : "_doc",
"_id" : "e7f84fa978a553e77716ab479d3d6ce5",
"_score" : null,
"_source" : {
"board" : {
"notApplied" : "2022-10-13T00:00:00.000Z"
},
"id" : "e7f84fa978a553e77716ab479d3d6ce5",
"studentName" : "Sam",
"userId" : "d84f9e5231daa902c37921de9126cad7"
},
"fields" : {
"dues" : [
-49
]
},
"sort" : [
1665619200000
]
},
{
"_index" : "applications",
"_type" : "_doc",
"_id" : "9cba9f6b0d7a28ef739b321291d00170",
"_score" : null,
"_source" : {
"board" : {
"notApplied" : "2022-09-20T00:00:00.000Z"
},
"studentName" : "Ctest17 ",
"id" : "9cba9f6b0d7a28ef739b321291d00170",
"userId" : "ddaf6d6162c8317fd90fec0b870132ce"
},
"fields" : {
"dues" : [
-72
]
},
"sort" : [
1663632000000
]
}
]
}
}
}
}
}
I am getting the exact results but it has been duplicated by userId.
i need a result in top_hits without duplicates or the buckets should be grouped by userId. also the result should be sort desc by (dues or notApplied) field.
can any one help me to resolve this?
Swagger/OpenAPI definition:
{
"openapi" : "3.0.1",
"info" : {
"title" : "OpenAPI definition",
"version" : "v0"
},
"servers" : [ {
"url" : "http://sandbox.test.com:8063/api/recs",
"description" : "Generated server url"
} ],
"paths" : {
"/data" : {
"get" : {
"tags" : [ "Data" ],
"operationId" : "getData",
"parameters" : [ {
"name" : "goal",
"in" : "query",
"required" : false,
"schema" : {
"$ref" : "#/components/schemas/GoalsEnum_User"
}
} ],
"responses" : {
"404" : {
"description" : "Not Found",
"content" : {
"*/*" : {
"schema" : {
"type" : "object"
}
}
}
},
"200" : {
"description" : "Result generated successfully",
"content" : {
"application/json" : {
"schema" : {
"type" : "array",
"items" : {
"oneOf" : [ {
"$ref" : "#/components/schemas/EventDataDto"
}, {
"$ref" : "#/components/schemas/FreeRideDataDto"
}]
}
}
}
}
}
}
}
}
},
"components" : {
"schemas" : {
"GoalsEnum_User" : {
"type" : "string",
"enum" : [ "User1", "User2" ]
},
"EventDataDto" : {
"type" : "object",
"allOf" : [ {
"$ref" : "#/components/schemas/ParentDataSchema_UserData"
}, {
"type" : "object",
"properties" : {
"rules" : {
"type" : "array",
"items" : {
"$ref" : "#/components/schemas/RuleDto"
}
}
}
}, {
"$ref" : "#/components/schemas/ParentDataSchema"
} ]
},
"FreeRideDataDto" : {
"type" : "object",
"allOf" : [ {
"$ref" : "#/components/schemas/ParentDataSchema"
}, {
"type" : "object",
"properties" : {
"completedRoutes" : {
"type" : "array",
"items" : {
"type" : "integer",
"format" : "int64"
}
},
"averageDistance" : {
"type" : "number",
"format" : "double"
},
"averageDuration" : {
"type" : "number",
"format" : "double"
}
}
}, {
"$ref" : "#/components/schemas/ParentDataSchema_UserData"
} ]
},
"ParentDataSchema" : {
"required" : [ "type" ],
"type" : "object",
"properties" : {
"type" : {
"type" : "string",
"enum" : [ "FREE_RIDE", "EVENT" ]
}
},
"discriminator" : {
"propertyName" : "type",
"mapping" : {
"EVENT" : "#/components/schemas/EventRecommendationDto",
"FREE_RIDE" : "#/components/schemas/FreeRideRecommendationDto"
}
}
},
"ParentDataSchema_UserData" : {
"required" : [ "type" ],
"type" : "object",
"properties" : {
"type" : {
"type" : "string",
"enum" : [ "FREE_RIDE", "EVENT" ]
}
},
"discriminator" : {
"propertyName" : "type",
"mapping" : {
"EVENT" : "#/components/schemas/EventRecommendationDto",
"FREE_RIDE" : "#/components/schemas/FreeRideRecommendationDto"
}
}
}
}
}
}
Generated Example:
[
{
"type": "FREE_RIDE",
"rules": [
{
"ruleId": 0,
"categoryId": 0,
"name": "string",
"type": "string",
"value": "string"
}
]
},
{
"type": "FREE_RIDE",
"completedRoutes": [
0
],
"averageDistance": 0,
"averageDuration": 0
}
]
Since there are specific values for the discriminating field "type", I expect the examples to have the correct value for detected types. Although the types were listed correctly, the type field is not set to the discriminating value.
Is there anything I can do to the Swagger/OpenAPI definitions or Swagger UI to fix this? I'm even open to adding a bug-fix if you can point me to where the values of the field examples are set and how can I choose the discriminating value instead of the first one in the enum instead.
I have 2 indexes products & shop_inventory_6(shop wise inventory)
products mapping
{
"products_staging" : {
"aliases" : { },
"mappings" : {
"product" : {
"properties" : {
"alternate_names" : {
"type" : "text"
},
"brand" : {
"properties" : {
"id" : {
"type" : "integer"
},
"image_url" : {
"type" : "text",
"index" : false
},
"name" : {
"type" : "text",
"analyzer" : "standard"
}
}
},
"brand_suggest" : {
"type" : "completion",
"analyzer" : "autocomplete",
"search_analyzer" : "whitespace_analyzer",
"preserve_separators" : true,
"preserve_position_increments" : true,
"max_input_length" : 50
},
"category" : {
"properties" : {
"id" : {
"type" : "integer"
},
"image_url" : {
"type" : "text",
"index" : false
},
"name" : {
"type" : "text",
"analyzer" : "standard"
}
}
},
"id" : {
"type" : "text"
},
"image_url" : {
"type" : "text",
"index" : false
},
"name" : {
"type" : "text",
"fields" : {
"raw" : {
"type" : "keyword"
}
},
"analyzer" : "standard"
},
"name_suggest" : {
"type" : "completion",
"analyzer" : "autocomplete",
"search_analyzer" : "whitespace_analyzer",
"preserve_separators" : true,
"preserve_position_increments" : true,
"max_input_length" : 50
},
"product_alternate_name_suggest" : {
"type" : "completion",
"analyzer" : "autocomplete",
"search_analyzer" : "whitespace_analyzer",
"preserve_separators" : true,
"preserve_position_increments" : true,
"max_input_length" : 50
},
"product_sizes" : {
"type" : "nested",
"properties" : {
"ean_code" : {
"type" : "keyword"
},
"id" : {
"type" : "integer"
},
"is_deleted" : {
"type" : "boolean"
},
"price" : {
"type" : "float"
},
"shop_category_type_ids" : {
"type" : "text"
},
"uom" : {
"type" : "keyword"
},
"weight" : {
"type" : "float"
}
}
},
"sub_category" : {
"properties" : {
"alternate_names" : {
"type" : "text"
},
"id" : {
"type" : "integer"
},
"image_url" : {
"type" : "text",
"index" : false
},
"name" : {
"type" : "text",
"analyzer" : "standard"
}
}
},
"sub_category_alternate_suggest" : {
"type" : "completion",
"analyzer" : "autocomplete",
"search_analyzer" : "whitespace_analyzer",
"preserve_separators" : true,
"preserve_position_increments" : true,
"max_input_length" : 50
},
"sub_category_suggest" : {
"type" : "completion",
"analyzer" : "autocomplete",
"search_analyzer" : "whitespace_analyzer",
"preserve_separators" : true,
"preserve_position_increments" : true,
"max_input_length" : 50
}
}
}
},
"settings" : {
"index" : {
"number_of_shards" : "3",
"provided_name" : "products_staging",
"creation_date" : "1566968865962",
"analysis" : {
"filter" : {
"autocomplete_filter" : {
"type" : "edge_ngram",
"min_gram" : "2",
"max_gram" : "20"
}
},
"analyzer" : {
"autocomplete" : {
"filter" : [
"lowercase",
"autocomplete_filter"
],
"type" : "custom",
"tokenizer" : "standard"
},
"whitespace_analyzer" : {
"filter" : [
"lowercase",
"asciifolding"
],
"type" : "custom",
"tokenizer" : "whitespace"
}
}
},
"number_of_replicas" : "1",
"uuid" : "M5GE3TK9QOKVaBMcOkCJPQ",
"version" : {
"created" : "6000199"
}
}
}
}
}
shop_inventory mapping
{
"staging_shop_inventory_17" : {
"aliases" : { },
"mappings" : {
"shop_inventory" : {
"properties" : {
"brand" : {
"properties" : {
"created_at" : {
"type" : "date"
},
"id" : {
"type" : "integer"
},
"image" : {
"type" : "text",
"index" : false
},
"is_selected" : {
"type" : "boolean"
},
"name" : {
"type" : "text",
"analyzer" : "standard"
},
"updated_at" : {
"type" : "date"
}
}
},
"brand_suggest" : {
"type" : "text",
"analyzer" : "ngram_analyzer"
},
"category" : {
"properties" : {
"id" : {
"type" : "integer"
},
"image" : {
"type" : "text",
"index" : false
},
"name" : {
"type" : "text",
"analyzer" : "standard"
}
}
},
"deleted_at" : {
"type" : "date"
},
"id" : {
"type" : "integer"
},
"image" : {
"type" : "text",
"index" : false
},
"is_deleted" : {
"type" : "boolean"
},
"name" : {
"type" : "text",
"fields" : {
"raw" : {
"type" : "keyword"
}
},
"analyzer" : "gramAnalyzer",
"search_analyzer" : "whitespace_analyzer"
},
"name_suggest" : {
"type" : "text",
"analyzer" : "ngram_analyzer"
},
"product_deleted" : {
"type" : "keyword"
},
"product_id" : {
"type" : "integer"
},
"product_sizes" : {
"type" : "nested",
"properties" : {
"deleted_at" : {
"type" : "date"
},
"ean_code" : {
"type" : "keyword"
},
"id" : {
"type" : "integer"
},
"in_stock" : {
"type" : "boolean"
},
"is_deleted" : {
"type" : "boolean"
},
"price" : {
"type" : "float"
},
"product_update_on" : {
"type" : "date"
},
"product_update_status" : {
"type" : "integer"
},
"uom" : {
"type" : "keyword"
},
"weight" : {
"type" : "float"
}
}
},
"sub_category" : {
"properties" : {
"created_at" : {
"type" : "date"
},
"id" : {
"type" : "integer"
},
"image" : {
"type" : "text",
"index" : false
},
"is_selected" : {
"type" : "boolean"
},
"name" : {
"type" : "text",
"analyzer" : "standard"
},
"updated_at" : {
"type" : "date"
}
}
},
"sub_category_suggest" : {
"type" : "text",
"analyzer" : "gramAnalyzer",
"search_analyzer" : "whitespace_analyzer"
}
}
}
},
"settings" : {
"index" : {
"number_of_shards" : "3",
"provided_name" : "staging_shop_inventory_17",
"creation_date" : "1569230448054",
"analysis" : {
"filter" : {
"gramFilter" : {
"token_chars" : [
"letter",
"digit"
],
"min_gram" : "1",
"type" : "edge_ngram",
"max_gram" : "20"
}
},
"analyzer" : {
"whitespace_analyzer" : {
"filter" : [
"lowercase",
"asciifolding"
],
"type" : "custom",
"tokenizer" : "whitespace"
},
"ngram_analyzer" : {
"token_chars" : [
"letter",
"digit"
],
"min_gram" : "4",
"type" : "custom",
"max_gram" : "20",
"tokenizer" : "ngram"
},
"gramAnalyzer" : {
"filter" : [
"lowercase",
"asciifolding",
"gramFilter"
],
"type" : "custom",
"tokenizer" : "whitespace"
}
}
},
"number_of_replicas" : "1",
"uuid" : "q9BkwXMVQnGoga8tznNFgg",
"version" : {
"created" : "6000199"
}
}
}
}
}
I want to select products from products index which are not in shop_inventory index. without two queries
Also I want select product by sub_category_id & brand_ids where I have multiple sub_category_id & brand ids (because my brand belongs to multiple categories) without using OR condition
I have generated some points of interest with my database with SQL to geoJSON.
geojson:
{
"FeatureCollection" : [
{
"geometry" : {
"coordinates" : [
-45.927083,
-12.260889
],
"type" : "Point"
},
"properties" : {
"grower" : "foo",
"name" : "bar",
"radius" : "626.46"
},
"type" : "Feature"
},
{
"geometry" : {
"coordinates" : [
-45.916500,
-12.255944
],
"type" : "Point"
},
"properties" : {
"grower" : "foo",
"name" : "bar",
"radius" : "565.04"
},
"type" : "Feature"
},
{
"geometry" : {
"coordinates" : [
-45.949417,
-12.270361
],
"type" : "Point"
},
"properties" : {
"grower" : "foo",
"name" : "bar",
"radius" : "631.47"
},
"type" : "Feature"
},
{
"geometry" : {
"coordinates" : [
-45.958833,
-12.277361
],
"type" : "Point"
},
"properties" : {
"grower" : "foo",
"name" : "bar",
"radius" : "591.85"
},
"type" : "Feature"
},
{
"geometry" : {
"coordinates" : [
-45.942944,
-12.249889
],
"type" : "Point"
},
"properties" : {
"grower" : "foo",
"name" : "bar",
"radius" : "644.67"
},
"type" : "Feature"
},
{
"geometry" : {
"coordinates" : [
-45.930917,
-12.243611
],
"type" : "Point"
},
"properties" : {
"grower" : "foo",
"name" : "bar",
"radius" : "644.67"
},
"type" : "Feature"
},
{
"geometry" : {
"coordinates" : [
-45.871917,
-12.197139
],
"type" : "Point"
},
"properties" : {
"grower" : "foo",
"name" : "bar",
"radius" : "574.60"
},
"type" : "Feature"
},
{
"geometry" : {
"coordinates" : [
-45.866861,
-12.206417
],
"type" : "Point"
},
"properties" : {
"grower" : "foo",
"name" : "bar",
"radius" : "574.60"
},
"type" : "Feature"
},
{
"geometry" : {
"coordinates" : [
-45.967389,
-12.261889
],
"type" : "Point"
},
"properties" : {
"grower" : "foo",
"name" : "bar",
"radius" : "592.50"
},
"type" : "Feature"
},
{
"geometry" : {
"coordinates" : [
-45.973500,
-12.250639
],
"type" : "Point"
},
"properties" : {
"grower" : "foo",
"name" : "bar",
"radius" : "592.50"
},
"type" : "Feature"
},
{
"geometry" : {
"coordinates" : [
-45.962944,
-12.245444
],
"type" : "Point"
},
"properties" : {
"grower" : "foo",
"name" : "bar",
"radius" : "621.60"
},
"type" : "Feature"
},
{
"geometry" : {
"coordinates" : [
-45.952667,
-12.239778
],
"type" : "Point"
},
"properties" : {
"grower" : "foo",
"name" : "bar",
"radius" : "592.50"
},
"type" : "Feature"
},
{
"geometry" : {
"coordinates" : [
-45.931639,
-12.228528
],
"type" : "Point"
},
"properties" : {
"grower" : "foo",
"name" : "bar",
"radius" : "574.60"
},
"type" : "Feature"
},
{
"geometry" : {
"coordinates" : [
-45.908694,
-12.247472
],
"type" : "Point"
},
"properties" : {
"grower" : "foo",
"name" : "bar",
"radius" : "557.20"
},
"type" : "Feature"
},
{
"geometry" : {
"coordinates" : [
-45.918667,
-12.239139
],
"type" : "Point"
},
"properties" : {
"grower" : "foo",
"name" : "bar",
"radius" : "644.50"
},
"type" : "Feature"
},
{
"geometry" : {
"coordinates" : [
-45.897028,
-12.246000
],
"type" : "Point"
},
"properties" : {
"grower" : "foo",
"name" : "bar",
"radius" : "557.20"
},
"type" : "Feature"
},
{
"geometry" : {
"coordinates" : [
-45.906417,
-12.230472
],
"type" : "Point"
},
"properties" : {
"grower" : "foo",
"name" : "bar",
"radius" : "64.50"
},
"type" : "Feature"
},
{
"geometry" : {
"coordinates" : [
-45.895750,
-12.225028
],
"type" : "Point"
},
"properties" : {
"grower" : "foo",
"name" : "bar",
"radius" : "644.50"
},
"type" : "Feature"
},
{
"geometry" : {
"coordinates" : [
-45.927111,
-12.213750
],
"type" : "Point"
},
"properties" : {
"grower" : "foo",
"name" : "bar",
"radius" : "564.90"
},
"type" : "Feature"
},
{
"geometry" : {
"coordinates" : [
-45.917639,
-12.208750
],
"type" : "Point"
},
"properties" : {
"grower" : "foo",
"name" : "bar",
"radius" : "564.90"
},
"type" : "Feature"
},
{
"geometry" : {
"coordinates" : [
-45.897833,
-12.198444
],
"type" : "Point"
},
"properties" : {
"grower" : "foo",
"name" : "bar",
"radius" : "584.00"
},
"type" : "Feature"
},
{
"geometry" : {
"coordinates" : [
-45.881583,
-12.202233
],
"type" : "Point"
},
"properties" : {
"grower" : "foo",
"name" : "bar",
"radius" : "574.60"
},
"type" : "Feature"
},
{
"geometry" : {
"coordinates" : [
-45.876833,
-12.235306
],
"type" : "Point"
},
"properties" : {
"grower" : "foo",
"name" : "bar",
"radius" : "574.60"
},
"type" : "Feature"
},
{
"geometry" : {
"coordinates" : [
-45.867278,
-12.230306
],
"type" : "Point"
},
"properties" : {
"grower" : "foo",
"name" : "bar",
"radius" : "574.60"
},
"type" : "Feature"
},
{
"geometry" : {
"coordinates" : [
-45.856806,
-12.224889
],
"type" : "Point"
},
"properties" : {
"grower" : "foo",
"name" : "bar",
"radius" : "574.60"
},
"type" : "Feature"
},
{
"geometry" : {
"coordinates" : [
-45.861806,
-12.215611
],
"type" : "Point"
},
"properties" : {
"grower" : "foo",
"name" : "bar",
"radius" : "574.60"
},
"type" : "Feature"
},
{
"geometry" : {
"coordinates" : [
-45.887833,
-12.192806
],
"type" : "Point"
},
"properties" : {
"grower" : "foo",
"name" : "bar",
"radius" : "12.60"
},
"type" : "Feature"
},
{
"geometry" : {
"coordinates" : [
-45.877639,
-12.187917
],
"type" : "Point"
},
"properties" : {
"grower" : "foo",
"name" : "bar",
"radius" : "564.90"
},
"type" : "Feature"
},
{
"geometry" : {
"coordinates" : [
-45.941889,
-12.234611
],
"type" : "Point"
},
"properties" : {
"grower" : "foo",
"name" : "bar",
"radius" : "644.50"
},
"type" : "Feature"
},
{
"geometry" : {
"coordinates" : [
-45.887111,
-12.239889
],
"type" : "Point"
},
"properties" : {
"grower" : "foo",
"name" : "bar",
"radius" : "644.50"
},
"type" : "Feature"
},
{
"geometry" : {
"coordinates" : [
-45.907944,
-12.203361
],
"type" : "Point"
},
"properties" : {
"grower" : "foo",
"name" : "bar",
"radius" : "591.70"
},
"type" : "Feature"
},
{
"geometry" : {
"coordinates" : [
-45.892722,
-12.208028
],
"type" : "Point"
},
"properties" : {
"grower" : "foo",
"name" : "bar",
"radius" : "574.60"
},
"type" : "Feature"
}
]
}
I would like to import this geojson to my code editor on Google Earth Engine. Looking in the docs (assets manager), GEE accepts assets as raster images, shapefiles (.shp, shx, dbf, prj).
Also, I found the import to feature collection via fusion tables, but it still needs shapefiles.
I have found some geojson to shapefile conversors, though I need a way to directly import my geojson to a feature collection on GEE. Is that possible?
You can also import GeoJSON geometry objects directly into either the JavaScript or Python API using, for example, this format for a MultiPolygon:
feature_geometry = {
"type": "MultiPolygon",
'coordinates": [
[
[
[-120, 35],
[-120.001, 35],
[-120.001, 35.001],
[-120, 35.001],
[-120, 35]
]
]
]
}
Both hash maps (i.e., dictionaries) are identical to the GeoJSON specification (source):
{
"type": "MultiPolygon",
"coordinates": [
[
[
[-120, 35],
[-120.001, 35],
[-120.001, 35.001],
[-120, 35.001],
[-120, 35]
]
]
]
}
Of course, you can also read this data in from a GeoJSON file (Python example shown):
import json
data = json.loads(geojson_file)
For a simple Python wrapper, there is the pygeoj library, but JSON data is handled well natively in Python and of course in JavaScript.
You can easily use OGR to convert your data a shapefile (which you can then upload through the code editor) or to KML and upload it into FusionTables.
ogr2ogr -f KML output.kml input.json
However, your FeatureCollection isn't valid GeoJSON and you'll have to fix that first. The preamble should look like:
{
"type": "FeatureCollection",
"features": [
{
"geometry" : { ...
I am unable to create a custom mapping for "hashtags," which is a subfield of "twitter_entities" in elasticsearch. I tried to do it in the following ways:
{
"mappings": {
"tweet" : {
"properties": {
"twitter_entities.hashtags" : {
"type" : "multi_field",
"fields" : {
"hashtag" : {
"type" : "string",
"analyzer" : "hashtag"
},
"autocomplete" : {
"type" : "string",
"index_analyzer" : "hashtag_autocomplete",
"search_analyzer" : "hashtag"
}
}
}
}
}
}
}
This creates another root field called "twitter_entities.hashtags"
{
"mappings": {
"tweet" : {
"properties": {
"hashtags" : {
"type" : "multi_field",
"fields" : {
"hashtag" : {
"type" : "string",
"analyzer" : "hashtag"
},
"autocomplete" : {
"type" : "string",
"index_analyzer" : "hashtag_autocomplete",
"search_analyzer" : "hashtag"
}
}
}
}
}
}
}
and
{
"mappings": {
"tweet" : {
"properties": {
"_parent" : {"type" : "twitter_entities" },
"hashtags" : {
"type" : "multi_field",
"fields" : {
"hashtag" : {
"type" : "string",
"analyzer" : "hashtag"
},
"autocomplete" : {
"type" : "string",
"index_analyzer" : "hashtag_autocomplete",
"search_analyzer" : "hashtag"
}
}
}
}
}
}
}
both just create another root field called "hashtags".
I am unable to find any documentation in the elasticsearch api or forums about doing this. Could anyone point me in the right direction?
Have a look at the documentation for mapping, especially the page about the object type.
You just have to define twitter_entitiesas an object and declare its fields under properties, same as you did for the root object (twitter_entities). You can omit the type object since any field that contains other fields under properties is detected as object anyway.
{
"mappings": {
"tweet" : {
"properties": {
"twitter_entities" : {
"type": "object",
"properties" : {
"hashtag" : {
"type" : "multi_field",
"fields" : {
"hashtag" : {
"type" : "string",
"analyzer" : "hashtag"
},
"autocomplete" : {
"type" : "string",
"index_analyzer" : "hashtag_autocomplete",
"search_analyzer" : "hashtag"
}
}
}
}
}
}
}
}
}