Elasticsearch

Elasticsearch,第1张

Elasticsearch

Elasticsearch在常规匹配查询中提供正则表达式支持

GET titles/movies/_search{    "query": {        "match" : { "titles.value" : "The * the *" }    }}

给你这个

{  "took": 4,  "timed_out": false,  "_shards": {    "total": 5,    "successful": 5,    "failed": 0  },  "hits": {    "total": 2,    "max_score": 1.6406528,    "hits": [      {        "_index": "titles",        "_type": "movies",        "_id": "4",        "_score": 1.6406528,        "_source": {          "id": "4",          "level": "second",          "titles": [ {   "value": "Bambi",   "type": "Educational",   "main": true }, {   "value": "The Baby Deer and the hunter (1942)",   "type": "Fantasy",   "main": false }          ]        }      },      {        "_index": "titles",        "_type": "movies",        "_id": "1",        "_score": 0.9026783,        "_source": {          "id": "1",          "level": "first",          "titles": [ {   "value": "The Bad and the Beautiful",   "type": "Catalogue",   "main": true }, {   "value": "The Bad and the Beautiful (1945)",   "type": "International",   "main": false }          ]        }      }    ]  }}

要更新到您的问题URI搜索,我不确定是否可行,如果使用curl进行 *** 作,则只需将查询dsl省略为数据即可

curl localhost:9200/titles/movies/_search -d '{"query":{"match":{"titles.value":"The * the *"}}}'{"took":46,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":2,"max_score":1.6406528,"hits":[{"_index":"titles","_type":"movies","_id":"4","_score":1.6406528,"_source":{"id": "4","level": "second","titles": [{"value": "Bambi","type": "Educational","main": true},{"value": "The Baby Deer and the hunter (1942)","type": "Fantasy","main": false}]}},{"_index":"titles","_type":"movies","_id":"1","_score":0.9026783,"_source":{"id": "1","level": "first","titles": [{"value": "The Bad and the Beautiful","type": "Catalogue","main": true},{"value": "The Bad and the Beautiful (1945)","type": "International","main": false}]}}]}}

更新至最新问题:

好吧,如果您想按级别排序,则需要为elasticsearch提供一个映射。我做了什么:

删除索引

DELETE titles

添加映射

PUT titles{  "settings": {    "number_of_shards": 1  },   "mappings": {    "movies": {      "properties": {        "level": {          "type": "keyword"        }      }    }  }}

优化查询DSL

GET titles/movies/_search{  "_source": [    "id",    "level",    "titles.value"  ],  "sort": [    {      "level": {        "order": "asc"      }    }  ],  "query": {    "match": {      "titles.value": "The * the *"    }  }}

那给我

{  "took": 4,  "timed_out": false,  "_shards": {    "total": 1,    "successful": 1,    "failed": 0  },  "hits": {    "total": 2,    "max_score": null,    "hits": [      {        "_index": "titles",        "_type": "movies",        "_id": "1",        "_score": null,        "_source": {          "level": "first",          "id": "1",          "titles": [ {   "value": "The Bad and the Beautiful" }, {   "value": "The Bad and the Beautiful (1945)" }          ]        },        "sort": [          "first"        ]      },      {        "_index": "titles",        "_type": "movies",        "_id": "4",        "_score": null,        "_source": {          "level": "second",          "id": "4",          "titles": [ {   "value": "Bambi" }, {   "value": "The Baby Deer and the hunter (1942)" }          ]        },        "sort": [          "second"        ]      }    ]  }}


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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存