0
votes

how can i query all the records that contains a specific string?

for example:

if those at the db

{
"ip": "185.239.131.76",
"domain": "http://express.com",
"event_type": "page_view"
},
{
"ip": "185.239.131.76",
"domain": "http://express.com",
"event_type": "page_view"
},
{
"ip": "37.39.244.71",
"domain": "http://express.com",
"event_type": "view"
},

and i want to fetch all records that contains the string "page"

so i get the only the first 2 of the 3 records above?

can show the http query and the nest query also?

thanks

2
show us your http query and nest query..user3775217

2 Answers

0
votes

You can try a post query :

http://localhost:9200/YourIndex/_search?=pretty=true

Query :

{
    "query": {
        "match": {
            "event_type": "page_view"
        }
    }
0
votes

If I understood your problem correctly, you have a field event_type which has values like page_view and view and maybe page_action, values are single strings though.

My approach to query for page in event_type would be to map event_type as not_analyzed like below mapping

"event_type": {
  "index": "not_analyzed",
  "type": "string"
},

And then query for strings starting with page like

GET yourIndex/_search
{ "query": {
    "prefix": {
      "event_type": {
          "value": "page"
      }
    }
}