0
我有這樣的文件:ElasticSearch查詢字段是否有值?
{
"took": 1,
"timed_out": false,
"_shards": {...},
"hits": {
"total": 20584,
"max_score": 8.143582,
"hits": [
{
"_index": "nyc_visionzero",
"_type": "logs",
"_id": "AVwMozs3iTTcr81oIxfl",
"_score": 8.143582,
"_source": {
"date": "02/12/2017",
"number_of_motorist_injured": 2,
"contributing_factor_vehicle": "Unsafe Speed",
}
...
我想所有那些領域contributing_factor_vehicle
包含文本unsafe
,如果我執行此查詢:
{
"query":{
"query_string": {
"query": "unsafe"
}
}
}
它返回一個包含所有結果不安全,但我想限制它到字段contributing_factor_vehicle
。
更新映射
{
"nyc_visionzero": {
"mappings": {
"logs": {
"_all": {
"enabled": true
},
"dynamic_templates": [
{
"string_fields": {
"match": "*",
"match_mapping_type": "string",
"mapping": {
"fields": {
"raw": {
"ignore_above": 256,
"type": "keyword"
}
},
"omit_norms": true,
"type": "text"
}
}
}
],
"properties": {
"@timestamp": {
"type": "date"
},
"@version": {
"type": "keyword"
},
"borough": {
"type": "keyword"
},
"contributing_factor_vehicle": {
"type": "keyword"
},
"coords": {
"type": "geo_point"
},
"cross_street_name": {
"type": "keyword"
},
"date": {
"type": "text",
"norms": false,
"fields": {
"raw": {
"type": "keyword",
"ignore_above": 256
}
}
},
"host": {
"type": "text",
"norms": false,
"fields": {
"raw": {
"type": "keyword",
"ignore_above": 256
}
}
},
"hour_of_day": {
"type": "integer"
},
"intersection": {
"type": "keyword"
},
"latitude": {
"type": "text",
"norms": false,
"fields": {
"raw": {
"type": "keyword",
"ignore_above": 256
}
}
},
"location": {
"type": "text",
"norms": false,
"fields": {
"raw": {
"type": "keyword",
"ignore_above": 256
}
}
},
"longitude": {
"type": "text",
"norms": false,
"fields": {
"raw": {
"type": "keyword",
"ignore_above": 256
}
}
},
"message": {
"type": "text",
"norms": false,
"fields": {
"raw": {
"type": "keyword",
"ignore_above": 256
}
}
},
"number_of_cyclist_injured": {
"type": "long"
},
"number_of_cyclist_killed": {
"type": "long"
},
"number_of_motorist_injured": {
"type": "long"
},
"number_of_motorist_killed": {
"type": "long"
},
"number_of_pedestrians_injured": {
"type": "long"
},
"number_of_pedestrians_killed": {
"type": "long"
},
"number_of_persons_injured": {
"type": "long"
},
"number_of_persons_killed": {
"type": "long"
},
"number_persons_impacted": {
"type": "long"
},
"off_street_name": {
"type": "keyword"
},
"on_street_name": {
"type": "keyword"
},
"query": {
"properties": {
"match_all": {
"type": "object"
}
}
},
"tags": {
"type": "text",
"norms": false,
"fields": {
"raw": {
"type": "keyword",
"ignore_above": 256
}
}
},
"time": {
"type": "text",
"norms": false,
"fields": {
"raw": {
"type": "keyword",
"ignore_above": 256
}
}
},
"unique_key": {
"type": "text",
"norms": false,
"fields": {
"raw": {
"type": "keyword",
"ignore_above": 256
}
}
},
"vehicle_type": {
"type": "text",
"norms": false,
"fields": {
"raw": {
"type": "keyword",
"ignore_above": 256
}
}
},
"zip_code": {
"type": "text",
"norms": false,
"fields": {
"raw": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}
我嘗試添加' 「default_field」: 「{contributing_factor_vehicle}」'和' 「default_field」: 「contributing_factor_vehicle」'我得到' 「命中」:{ 「總」:0, 「MAX_SCORE 「:null, 」hits「:[] }' – commonSenseCode
您可以分享映射嗎? 'GET索引/類型/ _mapping' – Richa
請參閱原始文章中的更新 – commonSenseCode