ElasticSearch:在嵌套数组中搜索字段

ElasticSearch:在嵌套数组中搜索字段,第1张

ElasticSearch:在嵌套数组中搜索字段

嵌套字段应使用嵌套查询进行搜索:

echo "Deleting old ElasticSearch index..."curl -XDELETe 'localhost:9200/arrtest'echoecho "Creating new ElasticSearch index..."curl -XPUT 'localhost:9200/arrtest/?pretty=1' -d '{   "mappings" : {      "cust2" : {         "properties" : { "firstName" : {    "type" : "string",    "analyzer" : "string_lowercase" }, "lastName" : {    "type" : "string",    "analyzer" : "string_lowercase" }, "paymentInfos": {     "properties": {         "billingZip": {  "type": "string",  "analyzer": "string_lowercase"         },         "paypalEmail": {  "type": "string",  "analyzer": "string_lowercase"         }     },     "type": "nested" }         }      }   },   "settings" : {      "analysis" : {         "analyzer" : { "uax_url_email" : {    "filter" : [ "standard", "lowercase" ],    "tokenizer" : "uax_url_email" }, "string_lowercase": {     "tokenizer" : "keyword",     "filter" : "lowercase" }         }      }   }}'echoecho "Index recreation finished"echo "Inserting one record..."curl -XPUT 'localhost:9200/arrtest/cust2/1' -d '{    "firstName": "john",    "lastName": "smith",    "paymentInfos": [{        "billingZip": "10101",        "paypalEmail": "[email protected]"    }, {        "billingZip": "20202",        "paypalEmail": "[email protected]"    }]}'echoecho "Refreshing index to make new records searchable"curl -XPOST 'localhost:9200/arrtest/_refresh' echoecho "Searching for record..."curl -XGET 'localhost:9200/arrtest/cust2/_search?pretty=1' -d '{    "sort": [],    "query": {        "bool": { "should": [], "must_not": [], "must": [{     "nested": {         "query": {  "query_string": {      "fields": ["paymentInfos.billingZip"],      "query": "10101"  }         },         "path": "paymentInfos"     } }]        }    },    "facets": {},    "from": 0,    "size": 25}'echo


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4937391.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-13
下一篇 2022-11-13

发表评论

登录后才能评论

评论列表(0条)

保存