Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
177 views
in Technique[技术] by (71.8m points)

elasticsearch - How to search in all attributes using DSL query?

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

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

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...