如果字段包含某些特定字符串,请搜索Elasticsearch 2.4(Search Elasticsearch 2.4 if a field contains some particular stri

编程入门 行业动态 更新时间:2024-10-22 09:26:23
如果字段包含某些特定字符串,请搜索Elasticsearch 2.4(Search Elasticsearch 2.4 if a field contains some particular string)

使用elasticsearch版本2.4.1,lucene版本5.5.2。

我面临的问题是我有以下文件:

{ "_index": "_myIndex", "_type": "_mytype", "_id": "76be12a4-037d-45e2-8941-8228287fcae4", "_source": { "eventID": "76be12a4-037d-45e2-8941-8228287fcae4", "receivedTimestamp": 1497591418899, "producerName": "_myProducer", "eventName": "event1", "message": "This is a query regarding elasticsearch. Return me this document if it contains elasticsearch", "timestamp": "1497591418000" } }

当我使用下面的查询进行搜索时,我看不到文档

curl -XGET 'http://localhost:9200/_myIndex/_search?pretty' -H 'Content-Type: application/json' -d '{ "query": { "match": { "message": "elasticsearch" }}}' Returns: { "took" : 8, "timed_out" : false, "_shards" : { "total" : 10, "successful" : 10, "failed" : 0 }, "hits" : { "total" : 0, "max_score" : null, "hits" : [ ] } }

任何帮助,将不胜感激。 我是Elasticsearch的新手。

索引的映射:

{ "_myIndex": { "mappings": { "_myType": { "properties": { "eventID": { "type": "string", "index": "not_analyzed" }, "eventName": { "type": "string", "index": "not_analyzed" }, "message": { "type": "string", "index": "no" }, "producerName": { "type": "string", "index": "not_analyzed" }, "query": { "properties": { "bool": { "properties": { "must": { "properties": { "range": { "properties": { "timestamp": { "properties": { "gte": { "type": "string" }, "lt": { "type": "string" } } } } }, "term": { "properties": { "eventName": { "properties": { "value": { "type": "string" } } } } } } } } } } }, "receivedTimestamp": { "type": "long" }, "size": { "type": "long" }, "timestamp": { "type": "long" } } } } } }

Used elasticsearch version 2.4.1, lucene version 5.5.2.

Issue I am facing is I am having documents like below:

{ "_index": "_myIndex", "_type": "_mytype", "_id": "76be12a4-037d-45e2-8941-8228287fcae4", "_source": { "eventID": "76be12a4-037d-45e2-8941-8228287fcae4", "receivedTimestamp": 1497591418899, "producerName": "_myProducer", "eventName": "event1", "message": "This is a query regarding elasticsearch. Return me this document if it contains elasticsearch", "timestamp": "1497591418000" } }

When I search using below query I don't get the document instead I see

curl -XGET 'http://localhost:9200/_myIndex/_search?pretty' -H 'Content-Type: application/json' -d '{ "query": { "match": { "message": "elasticsearch" }}}' Returns: { "took" : 8, "timed_out" : false, "_shards" : { "total" : 10, "successful" : 10, "failed" : 0 }, "hits" : { "total" : 0, "max_score" : null, "hits" : [ ] } }

Any help would be appreciated. I am newbie to Elasticsearch.

The mapping of the index:

{ "_myIndex": { "mappings": { "_myType": { "properties": { "eventID": { "type": "string", "index": "not_analyzed" }, "eventName": { "type": "string", "index": "not_analyzed" }, "message": { "type": "string", "index": "no" }, "producerName": { "type": "string", "index": "not_analyzed" }, "query": { "properties": { "bool": { "properties": { "must": { "properties": { "range": { "properties": { "timestamp": { "properties": { "gte": { "type": "string" }, "lt": { "type": "string" } } } } }, "term": { "properties": { "eventName": { "properties": { "value": { "type": "string" } } } } } } } } } } }, "receivedTimestamp": { "type": "long" }, "size": { "type": "long" }, "timestamp": { "type": "long" } } } } } }

最满意答案

问题在于您的message字段未编入索引( "index": "no" ),因此无法搜索。

您需要删除索引,然后修改您的消息字段映射到下面的映射,然后重新索引您的数据,它将工作。

"message": { "type": "string" },

The problem lies in the fact that your message field is not indexed ("index": "no"), hence not searchable.

You need to delete your index, then modify your message field mapping to the mapping below, then reindex your data and it will work.

"message": { "type": "string" },

更多推荐

本文发布于:2023-07-04 16:59:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1026904.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   字符串   Elasticsearch   field   Search

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!