Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How to check the value contain a string

Below is sample data. I need to search the any attributes which is Thomas

  • You can see I only have Thomas in first document. So first document has to return. Basically one document if any search field exists i need to retrieve that document
   {
       "id": "Accounting 101",
       "dataproduct": "E3",
       "professor": {
           "name": "Thomas Baszo",
           "department": "finance",
           "facutly_type": "part-time",
           "email": "baszot@onuni.com"
           },
       "students_enrolled": 27,
       "course_publish_date": "2015-01-19",
       "course_description": "Act 101 is a course from the business school on the introduction to accounting that teaches students how to read and compose basic financial statements"
   }
   
   PUT /data/test/2
   {
       "name": "Accounting 101",
       "room": "E3",
       "professor": {
           "name": "Sachin Baszo",
           "department": "finance",
           "facutly_type": "part-time",
           "email": "baszot@onuni.com"
           },
       "students_enrolled": 27,
       "course_publish_date": "2015-01-19",
       "course_description": "Act 101 is a course from the business school on the introduction to accounting that teaches students how to read and compose basic financial statements"
   }

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
176 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can use query string to search on any field.

GET /_search
{
  "query": {
    "query_string": {
      "query": "Thomas"
    }
  }
}

default_field (Optional, string) Default field you wish to search if no field is provided in the query string.

Defaults to the index.query.default_field index setting, which has a default value of *. The * value extracts all fields that are eligible for term queries and filters the metadata fields. All extracted fields are then combined to build a query if no prefix is specified.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...